True, False, and Beyond
| Operator | Name | Example | Result |
|---|---|---|---|
| > | Greater than | x > 10 | false |
| >= | Greater than or equal to | x >= 5 | true |
| < | Less than | x < -50 | false |
| <= | Less than or equal to | x <= 100 | true |
| == | Equal to | x == "5" | true |
| != | Not equal to | x != "b" | true |
| === | Equal value and type | x === "5" | false |
| !== | Not equal value or equal type | x !== "5" | true |
Assuming x = 5
var x = 99;
x == "99" //true
x === "99" //false
var y = null;
y == undefined //true
y === undefined //false"==" performs type coercion, while "===" does not
true == "1" //true
0 == false //true
null == undefined //true
NaN == NaN //false
| Operator | Name | Example | Result |
|---|---|---|---|
| && | AND | x < 10 && x !== 5 | false |
| || | OR | y > 9 || x === 5 | true |
| ! | NOT | !(x === y) | true |
Assuming x = 5 and y = 9
var x = 10;
var y = "a"
y === "b" || x >= 10var x = 3;
var y = 8;
!(x == "3" || x === y) && !(y != 8 && x <= y)Values that aren't actually true or false, are still inherently "truthy" or "falsey" when evaluated in a boolean context
!"Hello World"
!""
!null
!0
!-1
!NaN
Try These Examples:
Everything Else Is Truthy
Falsy Values:
var str = ""
var msg = "haha!"
var isFunny = "false"
!(( str || msg ) && isFunny)