if (condition) {
// code to be executed if the condition is true
} else {
// code to be executed if the condiyion is false
}
if (condition1) {
// code to be executed if the condition is true
} else if (condition2) {
/* code to be executed if the
condition1 is false and
condition2 is true */
} else {
/* code to be executed if
condition1 is false and
condition2 is false */
}
switch (expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
condition ? exprIFTrue : exprIfFalse
condition: An expression whose value is used as a condition.
exprIfTrue: An expression which is executed if the condition is truthy.
exprIfFalse: An expression which is executed if the condition is falsy.
- false
- 0 (zero)
- "", '', `` (empty strings)
- null
- undefined
- NaN (not a number)
- Everything that is not FALSY
for (st 1; st 2; st3) {
// code block to be executed
}
- st1 is executed (one time) before the execution of the code block.
- st2 defines the condition for executing the code block.
- st3 is executed (every time) after the code block has been executed.
while (condition) {
// code block to be executed
}
do {
// code block to be executed
} while (condition);
for (key in object) {
// code block to be executed
}
for (variable of iterable) {
// code block to be executed
}