Fundamentals Flashcards
The Six Primitive Values
numbers, strings, booleans, objects, functions, and undefined values
Arithmetic Operators
\+ Plus Addition - Minus Subtraction * Star Multiplication / Slash Division () Parens Grouping % Percent Modulus or Remainder
Special Number Values
Infinity Positive Infinity
-Infinity Negative Infinity
NaN Not a number
All three are special values considered of the number type but don’t behave like other numbers.
NaN == NaN
false
NaN is the only value in JS that is NOT equal to itself.
Logical Operators
&& (AND)
|| (OR)
! (NOT)
The Ternary Operator
( v1 ? v2 : v3 )
IF ‘first value’ THEN ‘second value’ ELSE ‘third value’
===
!==
Precision equality. JS will not attempt any type coercion when comparing using either of these two operators. Items compared with == and != are subject to type coercion.
The var statement
var name; var name = expression; var n1 = ex1, n2 = ex2;
A variable name with no assigned expression is evaluated as ‘undefined’.
Valid variable names
Are alphanumeric, must begin with a letter, and may contain underscore ‘_’ or dollar sign ‘$’ but no other punctuation or whitespace.
Coercion functions
Number()
String()
Boolean()
How do I check if a value is not a number or cannot be converted to a number?
isNaN(value) –> true
* or *
isNaN(Number(value)) –> true
Number(value) returns NaN if the value cannot be converted.
‘do … while’ loops
do {statements} while (expression);
Do statements at least once, then keep doing them until expression evaluates as false.
‘for’ loops
for (initialization; check; update) { statements; }
‘while’ loops
while (expression) { statements; }
break
Control jumps out of the enclosing loop.