JavaScript ES6 Flashcards

1
Q

What is a code block? What are some examples of a code block?

A

code block is a group of zero or more statements to be executed once it meets a condition. Examples: if else, for, do while, while, try catch.

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

What does block scope mean?

A

The scope created with a pair of curly braces

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

What is the scope of a variable declared with const or let?

A

blocked-scope

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

What is the difference between let and const?

A

let can be reassigned. const cannot be reassigned.

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

Why is it possible to .push() a new value into a const variable that points to an Array?

A

you’re not changing a property(key) value pair, you’re adding a new one onto it.

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

How should you decide on which type of declaration to use?

A

if you know you need to change variable later, use let, otherwise use const.

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

What is the syntax for writing a template literal?

A

let simple = this is a template literal; (text wrapped in backticks)

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

What is “string interpolation”?

A

the ability to substitute part of the string for the values of variables or expressions with special block ${variable_name}

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

What is destructuring, conceptually?

A

It assigns properties of an object to individual variables.

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

What is the syntax for Object destructuring?

A

let { property1: variable1, property2: variable2 } = object;

if same name for property and variable, more concise code

let { firstName, lastName } = person;

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

What is the syntax for Array destructuring?

A

let [x, y, z] = array;

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

How can you tell the difference between destructuring and creating Object/Array literals?

A

variable of the source object/array is to the right of the assignment operator for destructuring and to the left is the values to unpack from the sourced variable.

for creating a literal, const/let is to the left of the array/object variable name.

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

What is the syntax for defining an arrow function?

A

param => {
statements
}

(param1, paramN) => {
statements
}

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

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

With this syntax, the arrow function has an implicit return. No return statement, has to be an expression.

without the curly braces, you can only have one expression

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

How is the value of this determined within an arrow function?

A

the value of this is determined by the value of “this” in its containing code block

The arrow function retains the value of the this
In normal functions this is assigned at the value of call time
In arrow function this is being assigned at the time of definition

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

What is the JavaScript Event Loop?

A

The Event Loop is one of the four major concepts that sets JavaScript apart from many other languages

17
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

blocking is code that prevents further code from running until the current task is completed. it is on the stack.

non-blocking is asynchronous. it is off the stack.

18
Q

What are the three states a Promise can be in?

A

pending, fulfilled, rejected

19
Q

How do you handle the fulfillment of a Promise?

A

call the promise’s “then” method

20
Q

How do you handle the rejection of a Promise?

A

call the promise’s “catch” method

21
Q

What is Array.prototype.filter useful for?

A

The filter() method creates a new array with all elements that pass the test implemented by the provided function

22
Q

What is Array.prototype.map useful for?

A

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

23
Q

What is Array.prototype.reduce useful for?

A

To execute a reducer function (that you provide) on each element of the array, resulting in single output

24
Q

What is “syntactic sugar”?

A

Syntax designed to make things easier to read or to express.

25
Q

What is the typeof an ES6 class?

A

function

26
Q

Describe ES6 class syntax.

A

the keyword ‘class’ followed by the className, a constructor, and methods.

27
Q

What is “refactoring”?

A

Process of restructuring computer code without changing its external behavior. Intended to improve design/structure/implementation.

28
Q

How are ES Modules different from CommonJS modules?

A

A ES Modules syntax is more compact than CommonJS, structure can be statically analyzed, the support for cyclic dependencies is better than CommonJS

29
Q

What kind of modules can Webpack support?

A

A ECMAScript modules, AMD Modules, CommonJS

30
Q

What must the return value of myFunction be if the following expression is possible?
myFunction()();

A

return function

31
Q

What does this code do?
const wrap = value => () => value;

A
32
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

when it is defined

33
Q

What allows JavaScript functions to “remember” values from their surroundings?

A
34
Q
A