-
Notifications
You must be signed in to change notification settings - Fork 4
The Basics
Lev Brie edited this page Jan 19, 2016
·
3 revisions
number, string, boolean, undefined, null
- ints, floats, hexadecimal, etc., are all numbers
- Infinity, -Infinity, and NaN (not a number) are special values of type number
- the boolean data type has 2 possible values, true and false
- the null data type has only one value: null
- the undefined data type has only one value: undefined
There are 6 falsy values in JavaScript (everything else evaluates to true when converted to a boolean):
'', null, undefined, 0, NaN, false
'' is the escape character in JavaScript
', ", \, \n (newline), \r (carriage return), \t, \u (unicode)
!, &&, ||
Double negation converts any value to its boolean equivalent
!!0 will return false !!null will return false !!5 will return true !!'hey' will return true
Lazy Evaluation
var b = 5;
true || (b = 6);
console.log(b); // prints 5
true && (b = 6);
console.log(b); // prints 6
We can use this to provide lazy instantiation: var num = num || 6;
== DO NOT USE != DO NOT USE
Instead Use: ===, !==
, >=, <, <=
null is actually an object as well
Arrays are objects, and compared to the Arrays you're used to, they're very forgiving. We'll cover these in greater detail in future lessons.