JS Reserved Words Flashcards

1
Q

What is ‘this’?

A

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.

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

What are the JavaScript primitive data types?

A

7 primitives:

string, number, boolean, null, undefined, symbol, bigint

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

break;

A

the break statement ends the current loop, switch, or labeled block.

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

continue;

A

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.

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

return;

A

the return statement ends function/method execution and specifies a value to be returned to the caller.

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

switch case

A

the two keywords needed to assemble a switch statement.

switch(input) {
  case 'a': 
    //run some code
    break;
  default: 
    alert('no code ran');
    break;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

if (true)

else…

A

the if keyword defines a conditional expression

the else keyword defines a block of code if not true

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

for ()

A

creates a loop that will iterate ‘for’ a defined amount of iterations

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

while (true)

A

creates a loop that will iterate for an undefined amount of iterations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
do {
  //some code
}  while (true);
A

a do while expression will execute code exactly once before considering the while expression

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

true

false

A

reserved keywords for boolean values

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

typeof foobar

A

returns a string indicating the type of foobar

[ undefined, object, boolean, number, bigint, string, symbol, function, ]

note: null is a type of object

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

foo instanceof bar

A

the instance of operator tests if the prototype property of a constructor appears in the prototype chain of an object.

returns true||false

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

delete

A

the delete operator removes a property from an object.

delete object.property;

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

in

A

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;

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

const

A

const foo = ‘bar’

Constants are block-scoped. The value of a constant can’t be changed through reassignment (i.e. by using the assignment operator), and it can’t be redeclared.

However, if a constant is an object or array its properties or items can be updated or removed.

17
Q

let

A

The let declaration declares a block-scoped local variable, optionally initializing it to a value.

18
Q

var

A

The var statement declares a function-scoped or globally-scoped variable, optionally initializing it to a value.

19
Q

Which is preferrable to use ‘let’ or ‘var’

A

The vast majority of the time, ‘let’ is preferable to use for variable containers.

20
Q

import

A

The static import declaration is used to import read-only live bindings which are exported by another module.

The imported bindings are called ‘live bindings’ as they are updated by the module that exported the binding, and cannot be modified by the importing module.

In order to use the import declaration in a source file, the file must be interpreted by the runtime as a module. In HTML, this is done by adding type=”module” to the tag.
Modules are automatically interpreted in strict mode.

import declarations can only be present in modules, and only at the top-level (i.e. not inside blocks, functions, etc.).

21
Q

What are the four forms of import declarations?

A
Named import: 
  import { export1, export2 } from "module-name";
Default import: 
  import defaultExport from "module-name";
Namespace import: 
  import * as name from "module-name";
Side effect import: 
  import "module-name";
22
Q

export

A

The export declaration is used to export values from a JavaScript module.

23
Q

export default

A

The export default syntax allows any expression.

As a special case, functions and classes are exported as declarations, not expressions, and these declarations can be anonymous.

This means functions will be hoisted.

24
Q

async

A
async function (parameter) { 
  const result = await expression;
  return result; 
}

An async function is a function declared with the async keyword, and the await keyword is permitted within it.

The async and await keywords enable asynchronous, promise-based behavior to be written in a cleaner style, avoiding the need to explicitly configure promise chains.

25
Q

await

A

The await expression causes async function execution to pause until a Promise is settled (that is, fulfilled or rejected).
AND to resume execution of the async function after fulfillment.

When resumed, the value of the await expression is that of the fulfilled Promise.

If the Promise is rejected, the await expression throws the rejected value.

It can only be used inside an async function within regular JavaScript code. However, it can be used on its own with JavaScript modules.

26
Q

null

A

The value null represents the intentional absence of any object value. It is one of JavaScript’s primitive values and is treated as falsy for boolean operations.

27
Q

class Name {}

A

The class declaration creates a new class with a given name using prototype-based inheritance.

class name {
  constructor()
}
28
Q

static

A

The static keyword defines a static method or property for a class, or a class static initialization block.

Neither static methods nor static properties can be called on instances of the class. Instead, they’re called on the class itself.

class Name {
  static value;
  constructor()
  static function(){}
}
29
Q

extends

A

The extends keyword is used in class declarations or class expressions to create a class that is a child of another class.

30
Q

constructor()

A

The constructor method is a special method of a class for creating and initializing an object instance of that class.

31
Q

super

A

The super keyword is used to access properties on an object literal or class’s [[Prototype]], or invoke a superclass’s constructor.

32
Q

try, catch, finally

A

The try…catch statement is comprised of a try block and either a catch block, a finally block, or both.

The code in the try block is executed first, and if it throws an exception, the code in the catch block will be executed.

The code in the finally block will always be executed before control flow exits the entire construct.

33
Q

throw

A

The throw statement throws a user-defined exception. Execution of the current function will stop
(the statements after throw won’t be executed),

and control will be passed to the first catch block in the call stack. If no catch block exists among caller functions, the program will terminate.

34
Q

for await…of

A

The for await…of statement creates a loop iterating over async iterable objects as well as on sync iterables,

including: built-in String, Array, Array-like objects (e.g., arguments or NodeList), TypedArray, Map, Set, and user-defined async/sync iterables.

This statement can only be used inside an async function.

async function* foo() {
yield 1;
yield 2;
}

(async function() {
    for await (const num of foo()) {
        console.log(num);
        break; // closes iterator, triggers return
    }
})();
35
Q

for. .. in

for. .. of

A

***less performant that .forEach() and standard for()

The for…in statement iterates over all enumerable properties of an object that are keyed by strings (ignoring ones keyed by Symbols), including inherited enumerable properties.

The for…of statement creates a loop iterating over iterable objects, including: built-in String, Array, array-like objects (e.g., arguments or NodeList), TypedArray, Map, Set, and user-defined iterables. It invokes a custom iteration hook with statements to be executed for the value of each distinct property of the object.