JS Conditionals

Booleans

    

let bool1 = true;
let bool2 = false;


    

if

    

if (1 > 0) {

}


    

if...else

    

if (1 > 0) {

} else {

}


    

if/else if/else

    

if (1 > 0) {

} else if (2 > 0) {

} else {

}


    
    

if (1 > 0) {

} else if (2 > 0) {

} else if (3 > 0) {

} else {

}


    

Comparison operators

    

>
<
>=
<=
==
===
!=
!==


    

AND operator

    

if (1 > 0 && 2 > 1) {

}


    

OR operator

    

if (1 > 0 || 2 < 1) {

}


    

NOT operator

    

if (!false) {

}


    

switch statement

    

const myString = 'First';

switch (myString) {
  case 'First':
    // Insert code here
    break;
  case 'Second':
    // Insert code here
    break;
  default:
    // Insert code here
}


    

Ternary operator

    

condition ? exprIfTrue : exprIfFalse


    

Falsy values

    

false
0
-0
0n
"", '', ``
null
undefined
NaN
document.all


    

Truthy values

    
// Any value not found in the list of falsy values is considered truthy.