Fundamentals Flashcards

(37 cards)

1
Q

The Six Primitive Values

A

numbers, strings, booleans, objects, functions, and undefined values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Arithmetic Operators

A
\+    Plus       Addition
-    Minus     Subtraction
*    Star        Multiplication
/    Slash      Division
()    Parens    Grouping
%   Percent  Modulus or Remainder
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Special Number Values

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

NaN == NaN

A

false

NaN is the only value in JS that is NOT equal to itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Logical Operators

A

&& (AND)
|| (OR)
! (NOT)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The Ternary Operator

A

( v1 ? v2 : v3 )

IF ‘first value’ THEN ‘second value’ ELSE ‘third value’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

===

!==

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The var statement

A
var name;
var name = expression;
var n1 = ex1, n2 = ex2;

A variable name with no assigned expression is evaluated as ‘undefined’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Valid variable names

A

Are alphanumeric, must begin with a letter, and may contain underscore ‘_’ or dollar sign ‘$’ but no other punctuation or whitespace.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Coercion functions

A

Number()
String()
Boolean()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do I check if a value is not a number or cannot be converted to a number?

A

isNaN(value) –> true
* or *
isNaN(Number(value)) –> true
Number(value) returns NaN if the value cannot be converted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

‘do … while’ loops

A

do {statements} while (expression);

Do statements at least once, then keep doing them until expression evaluates as false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

‘for’ loops

A

for (initialization; check; update) { statements; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

‘while’ loops

A

while (expression) { statements; }

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

break

A

Control jumps out of the enclosing loop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

continue

A

Control jumps out of the loop body and the loop begins again at the beginning.

17
Q

switch

A
switch (expr) {
   case label_1:
   statements;
   [break];
   ...
   case label_2:
   ...
}
18
Q

if and else statements

A
if (expression) { statement; }
else if (expression) { statement; }
else { statement; }
19
Q

function statement

A

var func_name = function (params) { body; };

The curly braces are not optional, no matter how short the body is.

20
Q

function declaration

A

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.

21
Q

“Optional” function arguments

A

If args > parameters, then the additional arguments are ignored. If args < parameters, the missing parameters are assigned the value undefined.

22
Q

Arrays

A

Store an ordered sequence of values. Array literals are created by separating the values with commas and wrapping the whole in square brackets.

23
Q

Getting Properties

A

Two ways. Direct naming via dot notation and evaluative access via square brackets.

24
Q

Methods

A

properties that contain function values are called methods.

25
Objects
``` Arbitrary collections of properties. Syntax: var object_name = { 'prop name': value_expression, prop2: val_exp, }; ```
26
The delete operator
A unary operator that deletes a property from an object. delete obj_name.prop_name delete obj_name["prop name"]
27
Object property assignment
obj_name["prop_name"] = value | will assign the value to the property of the object. If the property does not exist it is created.
28
The in operator
"string" in object | A binary operator applied to a string and an object that will return true if the string names a property of the object.
29
Mutable and Immutable values
Objects are mutable. Arrays are a special case of objects, therefore they are mutable. Numbers, Strings, and Booleans are Immutable.
30
Object Comparison
name1 == name2 will return true only if both object names refer to the same object, false otherwise - even if name1 and name2 refer to separate objects that have identical contents. There is no 'deep' comparison operator built-in.
31
Looping over the properties of an object
for (var elem in object) { do whatever to elem; do whatever to object['elem']; } This is very pythonic - essentially a python for statement. It loops over the elements of the object.
32
The arguments object
When a function is called, a special variable named arguments is created for that local environment - it stores the arguments that were passed to the function. The arguments object is a lot like an array but it supports no array methods. It does however have a length property and it's elements can be accessed via index (i.e. arguments[x] gets the value at x).
33
The Math object
``` A container for a bunch of mathematical stuff. Properties: max min floor ceil round PI random * trig stuff --> sin, cos, tan, etc. ```
34
The Global object
The object where each global variable is stored. In browsers, the global scope object is stored in the window variable.
35
JSON
JavaScript Object Notation Very similar to objects and arrays with some restrictions: 1. All property names are wrapped in double quotes 2. No comments allowed. 3. Only simple data types - no function calls, etc.
36
JSON.stringify(value)
takes a JS value and returns a JSON encoded string
37
JSON.parse(string)
Takes a JSON encoded string and returns the value it encodes.