JavaScript · Beginner level

Beginner level · Module 2 of 5 · 11 guided hours

Logic and Functions in JavaScript

Make decisions with conditions, repeat work with loops, and organise code into functions, including arrow functions.

Learning objectives

  • Write conditions using strict equality and logical operators
  • Use loops to repeat work
  • Write function declarations and arrow functions with parameters and return values

Topics

  • === vs ==
  • truthy and falsy
  • if/else and switch
  • for, while and for...of
  • function declarations and arrow functions
  • parameters, defaults and scope

Lessons

  1. Lesson 1 Conditions and Comparisons

    Make decisions with if/else and switch, compare values with strict equality and understand truthy and falsy values.

    strict equality ===&&, || and !truthy and falsyswitch

  2. Lesson 2 Loops

    Repeat work with for, while and for...of loops, and stop loops early when needed.

    for loopwhile loopfor...ofbreak and continue

  3. Lesson 3 Functions and Arrow Functions

    Write reusable functions with parameters, default values and return values, using declarations and arrow functions.

    function declarationarrow functiondefault parametersblock scope

Practical activity

Write a function library for a school: grade a mark, decide whether fees are fully paid and count passes in a list of marks.

Expected outcomes

  • Correct decisions and loops
  • Small, reusable functions

Assessment

Practical: write four functions that pass a set of provided console checks.

Free taster lesson Control Flow & Functions Read a free self-study lesson on this topic in the Free Course Library.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.