Branching and Boolean Expressions

If the embed above does not work here is a link to the full version of the video

Branching - if, else if, else

We can use if, else if and else in JavaScript. Each if statement will check whether a given condition (boolean expression) is true or false. If true, it will execute the block of code it contains. If false it will skip over the block to the next section of code.

if (true) {
let myName = "martin";
}
let x = 6;
if (x % 2 === 0) {
console.log("X is even");
} else {
console.log("X is odd");
}

false

Almost everything is true in JavaScript, except for:

Code examples

There are a set of code examples that accompany this course showing the use of JavaScript. (Right click and open in a new window/tab) if you’re viewing this on Learning Central.