Section 3: Types and Operators Flashcards
Dynamic typing
You don’t tell the javascript engine what type of data a variable holds, the engine figures it out while your code is running/executing.
Variables can hold different types of values because it’s all figured out during execution. (“figuring things out on the fly”)
Static typing
You tell the engine/compiler ahead of time what kind of data you intend to hold inside of a variable.
This is NOT what the javascript engine does. Javascript is dynamically typed, there is no keyword that tells the engine what kind of data you intend to put inside of the variable.
Primitive type
A type of data that represents a single value. That is, not an object.
undefined
A primitive type. undefined represents lack of existence (you shouldn’t set a variable to this)
null
A primitive type. null represents lack of existence (you CAN set a variable to this…leave undefined to the javascript engine)
boolean
A primitive type. true or false
number
A primitive type. This is the only numeric type in javascript and it is a floating point number (there’s always some decimals).
Unlike other programming languages, there’s only one ‘number’ type… and it can make math weird.
string
A primitive type. A sequence of characters (both ‘’ and “” can be used)
symbol
A primitive type. Used in ES6 (next version of Javascript). Not fully supported as of Q4 2015.
operator
A special function that is syntactically (written) differently.
Generally, operators take TWO parameters and return ONE result.
infix notation
operator sits between two parameters (as opposed to prefix notation)
Operator Precedence
Which operator function gets called first.
Functions are called in order of precedence (HIGHER precedence wins.)
[Operator] Associativity
What order operator functions get called in: left-to-right OR right-to-left.
Note: When functions have the SAME PRECEDENCE
var a = 2, b = 3, c = 4; a = b = c; console.log(a); console.log(b); console.log(c);
What is logged in the console?
4
4
4
Assignment operator (=) has a precedence of 3 and its associativity is right-to-left (aka right associative)
Coercion
Converting a value from one type to another.
This happens quite often in Javascript because it’s dynamically typed.
var a = 1 + ‘2’; returns string ‘12’ because 1 is coerced into being a string representation of integer 1.