If - Else

You can put anything into an "if" statement.
Only null, undefined, 0, false and empty string will be evaluated to False. Everything else is True.
The if statement is often used to check if a variable is null or undefined.


if (condition) { } 

if (true) { } // true
if (false) { } // false
if ("text") { } // true
if ("") { } // false
if (200) { } // true
if (0) { } // false
if (20/0) { } // false
if (null) { } // false
if (undefined) { } // false

if (condition) { 

} else {

}

if (x === 10) { 

} else if (x === 20) {

} else if {

} else {

}

Immediate IF / Conditional Operator

if true ? "one" : "two" 




© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext