JavaScript Flashcards

1
Q

When we run our code, what is created?

A

The Global Execution Context

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

The Global Execution Context consists of which two things?

A

1) Thread of Execution

2) Global Variable Environment or Global Memory

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

When we execute a function, what is created?

A

The Local Execution Context or the Function Execution Context

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

What is the Thread of Execution?

A

It parses and executes the code line by line

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

The Local Execution Context consists of which two things?

A

1) Thread of Execution

2) Variable Environment or Local Memory

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

What is the Variable Environment?

A

It is live memory of variables with data in the function

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

What is the Global Variable Environment?

A

It is live memory of variables with data

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

What is the first item on the Call Stack?

A

The Global Execution Context

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

When is an item pushed onto the Call Stack?

A

When a function is called, it is ‘pushed’ on the stack. When it is finished then it is ‘popped’ off the stack.

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

What is a function parameter?

A

The name listed in the function’s definition

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

What is a function argument?

A

The real value passed into the function

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

What are the primitive types in JavaScript?

A

strings, numbers, booleans, undefined, and null

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

What is stored in the Stack?

A

Primitives and References because they are fixed size. The size is known at compile time. This is static memory allocation.

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

What is stored in the Heap?

A

Objects and Functions. The size is known at runtime. This is dynamic memory allocation.

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

Do variables point at the Stack or the Heap?

A

All variables point at the Stack. For objects and functions, the Stack has a reference address to find them in the Heap.

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

What JavaScript engine does Chrome use?

A

V8

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

What JavaScript engine does Node.js use?

A

V8

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

What JavaScript engine does Firefox use?

A

SpiderMonkey

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

What JavaScript engine does Safari use?

A

JavaScriptCore

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

What JavaScript engine does Edge use?

A

V8, but used to be Chakra

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

What is an IIFE?

A

Immediately Invoked Function Expression. It is a self-executing anonymous function.

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

What is a variable?

A

It is a named container for storing values

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

What are variable names called in JS?

A

Identifiers

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

What is scope?

A

Scope defines the lifetime and visibility of a variable.

Scope === Variable Access

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

What is the global object?

A

The global object is an object that always exists in the global scope.

1) Web Browsers have the ‘window’ object
2) Node has the ‘global’ object

26
Q

What are the different kinds of scope?

A

1) Global scope
2) Function scope
3) Block scope
4) Module scope

27
Q

What is Global scope?

A

Variables defined outside of any function, block, or module have Global scope. Variables in Global scope can be accessed anywhere in the application. Global variables are available for the lifetime of the application.

28
Q

What is Function scope?

A

Variables defined in a function are visible everywhere within a function, but not visible outside the function. Function scope is only applicable to variables declared with the ‘var’ keyword.

29
Q

What is Block scope?

A

It is defined with curly braces. It could be functions, loops, if statements, etc. Block scope is only applicable to variables declared with the keywords ‘let’ or ‘const’.

30
Q

What is Module scope?

A

Variables defined inside a module are hidden and not available to any other module unless it is explicitly exported.

31
Q

What is Lexical scope?

A

It is when a child scope has access to the parent scope.

32
Q

What is scope chain?

A

Every scope has a link to its parent scope. When a variable is used, it looks down the scope chain until it finds the requested variable or it reaches the Global scope.

33
Q

What is a closure?

A

A closure is an object that combines two things: a function, and the environment in which the function was created. The environment contains any local variables that were in-scope at the time the closure was created.

34
Q

What is Hoisting?

A

Hoisting is a mechanism where variable and function declarations are moved to the top of their scope before code execution.

35
Q

What happens when Hoisting a variable?

A

When ‘var’ is hoisted to the top of its scope, it is declared and initialized to undefined.
When ‘let’ and ‘const’ are hoisted to the top of their scope, they are declared but inaccessible until their formal declaration.

36
Q

What is the Temporal Dead Zone?

A

This is in reference to hoisting with ‘let’ and const’. Between their declaration are the top of the scope and their formal declaration in code, they are inaccessible, which is the Temporal Dead Zone.

37
Q

What is a function declaration?

A
A function declaration is the creation of a function starting with the function keyword. Eg. 
function greeting() {
  // Some Code
}
38
Q

What is a function expression?

A
A function expression is a function assigned to a variable. Eg.
const greeting = function() {
  // Some Code
};
39
Q

What happens when hoisting a function?

A

A function declaration is hoisted to the top of its scope and initialized with it’s function value.
A function expression’s variable is hoisted to the top of its scope, but initialized to undefined, unless it is ‘let’ or ‘const’ then it is inaccessible due to the TDZ

40
Q

What is a pure function?

A

1) A function is pure when given the same input, it will always return the same output.
2) It also produces no side effects.

41
Q

What is a Higher Order Function?

A

It is a function that takes a function as a parameter and/or returns a function.

42
Q

What are the two phases of the Global Execution Context?

A

1) Creation Phase

2) Execution Phase

43
Q

What happens in the Creation Phase for the Global Execution Context?

A

1) Create the global object (eg. window in browser)
2) Initializes the value of ‘this’ (which is equal to global object)
3) Set aside memory space for variables (Set undefined)
4) Store function declarations in memory

44
Q

What happens in the Execution Phase for the Global Execution Context/Function Execution Context?

A

It executes the code line by line

45
Q

What happens in the Creation Phase for the Function Execution Context?

A

1) Create the arguments object
2) this keyword
3) Set aside memory space for variables
4) Set parameter(s) to argument value(s)

46
Q

What is the Event Loop?

A

The event loop handles asynchronous tasks. It is implemented by the browser or by nodejs, and not by the JavaScript engine. It picks up tasks from the message queue or job queue.

47
Q

What is the message queue?

A

When asynchronous tasks, called by the browser’s API, are completed, they are placed in the message queue waiting to be picked up by the event loop. They will be placed on the call stack as soon as it is empty.

48
Q

What is the job queue?

A

The job queue is for micro tasks. Promises and Async/Await get to skip the message queue and will be executed first.

49
Q

What is the ‘this’ keyword?

A

The ‘this’ keyword represents the object that is executing the current function.

1) method -> ‘this’ represents the object the method is being called on.
2) function declaration -> ‘this’ represents the global object
3) arrow function -> ‘this’ represents the object the function is called on

50
Q

What is array destructuring?

A

let [one, two] = [true, false];

Brackets for both, and order indicates assignment

51
Q

What is object destructuring?

A

let { first, second } = { first: 1, second: 2 };

Braces for both, and name/label indicates assignment

52
Q

How to swap variables without using a temp?

A
let a = 1, b = 2; 
[b, a] = [a, b];
53
Q

What is the spread operator?

A

let a = [1, 2, 3];
let b = [4, 5, 6];
let c = […a, …b];

It takes an array of values of spreads them across arguments or elements.

54
Q

What is the rest operator?

A

The rest parameter allows us to pass an indefinite number of parameters to a function and access them in an array.

55
Q

When do you use let?

A

Same as var but has scope implications. eg. Block scope vs function scope (var)

56
Q

When do you use const?

A

When you don’t want a primitive to change value, or you don’t want an object to change type.

57
Q

What is the void operator?

A

It evaluates the given expression and then returns undefined. eg. void 0 returns undefined.

58
Q

What is the delete operator?

A

It removes a property from an object.

It removes an element from an array, but the length remains the same.

59
Q

How is a generator defined?

A
It is defined with an asterisk. Calling a generator returns a Generator object. 
eg. function* generator(i) {
  yield i;
  yield i + 10;
}
60
Q

What is the yield keyword?

A

It is used to pause and resume a generator function.

61
Q

What is the get keyword?

A

It can be used on an object to create a getter. This is a function to create a computed property. It is a function but accessed like a property.