JS Reserved Words Flashcards
What is ‘this’?
refers to an object:
In an object method, this refers to the object.
In an object’s prototype chain, this refers to the object.
In a function, in strict mode, this is undefined.
In an event, this refers to the element that received the event.
Alone, this refers to the global object.
In a function, this refers to the global object.
methods like call(), apply(), and bind() can refer this to any object.
What are the JavaScript primitive data types?
7 primitives:
string, number, boolean, null, undefined, symbol, bigint
break;
the break statement ends the current loop, switch, or labeled block.
continue;
the continue statement ends the current iteration of a loop.
i.e. if we are on the 9th iteration and hit a continue statement, we’ll skip to the 10th iteration.
return;
the return statement ends function/method execution and specifies a value to be returned to the caller.
switch case
the two keywords needed to assemble a switch statement.
switch(input) { case 'a': //run some code break; default: alert('no code ran'); break; }
if (true)
else…
the if keyword defines a conditional expression
the else keyword defines a block of code if not true
for ()
creates a loop that will iterate ‘for’ a defined amount of iterations
while (true)
creates a loop that will iterate for an undefined amount of iterations.
do { //some code } while (true);
a do while expression will execute code exactly once before considering the while expression
true
false
reserved keywords for boolean values
typeof foobar
returns a string indicating the type of foobar
[ undefined, object, boolean, number, bigint, string, symbol, function, ]
note: null is a type of object
foo instanceof bar
the instance of operator tests if the prototype property of a constructor appears in the prototype chain of an object.
returns true||false
delete
the delete operator removes a property from an object.
delete object.property;
in
the in operator returns true if the specified property exists in the object’s prototype chain
‘propertyName’ in object;
if (‘propertyName’ in object === false) //do this code;