June 2016
Beginner
314 pages
6h 19m
English
JavaScript has a similar set of control structures as the C and Java languages. Conditional statements are supported by if...else and switch. Loops are supported by the while, do...while, and for constructs.
The first conditional statement we will take a look at is the if...else construct. There are a few ways we can use the if...else construct.
We can use the if statement if we want to execute a script only if the condition is true, as follows:
var num = 1;
if (num === 1) {
console.log("num is equal to 1");
}
We can use the if...else statement if we want to execute a script and the condition is true or another script just in case the condition is false (else), as follows:
var num = 0; if (num === 1) { console.log("num ...Read now
Unlock full access