Skip to content
Lev Brie edited this page Jan 19, 2016 · 3 revisions

Next (Functions) ►

5 Primitive Data Types:

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

Special Strings

'' is the escape character in JavaScript

', ", \, \n (newline), \r (carriage return), \t, \u (unicode)

Logical Operators

!, &&, ||

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;

Comparison Operators

== DO NOT USE != DO NOT USE

Instead Use: ===, !==

, >=, <, <=

Everything else is an object

null is actually an object as well

Arrays, Objects & Functions

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.