Fundamentals Flashcards
(37 cards)
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.
continue
Control jumps out of the loop body and the loop begins again at the beginning.
switch
switch (expr) { case label_1: statements; [break]; ... case label_2: ... }
if and else statements
if (expression) { statement; } else if (expression) { statement; } else { statement; }
function statement
var func_name = function (params) { body; };
The curly braces are not optional, no matter how short the body is.
function declaration
function name (params) { body; };
A function may be declared anywhere in the scope and calls to it will still work. Function declarations are read before execution begins.
“Optional” function arguments
If args > parameters, then the additional arguments are ignored. If args < parameters, the missing parameters are assigned the value undefined.
Arrays
Store an ordered sequence of values. Array literals are created by separating the values with commas and wrapping the whole in square brackets.
Getting Properties
Two ways. Direct naming via dot notation and evaluative access via square brackets.
Methods
properties that contain function values are called methods.