ES6 Flashcards

1
Q

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

A

A code block is code contained between a pair of curly braces. E.g. { const a = 5; console.log(a); }

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

What does block scope mean?

A

A variable with block scope is accessible only within the code block it was declared in.

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

Block 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

const variables cannot be reassigned, let variables can.

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

Because the variable address is not being changed.

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

Use const unless you need to reassign let.

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

Write string in between backticks like this

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

What is “string interpolation”?

A

Substituting a piece of the string for results of expressions.

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

What is destructuring, conceptually?

A

Taking the value of a property from an object and assigning it to a variable.

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

const { variable } = objectExample;

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

const [one, two, three] = [1, 2, 3];

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

In destructuring, the brackets are on the left of the assignment operator, whereas when Object/Array literals are being created the brackets are on the right.

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

parameter => code;
e.g. x => x + 2;
Add parentheses if more than one parameter and curly braces if more than one line of code.

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

There can only be one expression and no statements.

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

In an arrow function, this captures the this value of its enclosing context during definition instead of creating its own during call time.

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

What are the three states a Promise can be in?

A

Pending, fulfilled, and rejected.

17
Q

How do you handle the fulfillment of a Promise?

A

.then(result => {})

18
Q

How do you handle the rejection of a Promise?

A

.catch(err => {})

19
Q

What is “syntactic sugar”?

A

Syntax within a language to make things easier to express and read.

20
Q

What is the typeof an ES6 class?

A

function

21
Q

Describe ES6 class syntax.

A

class {
constructor(params) { codeblock }
method() { codeblock }
}

22
Q

What is “refactoring”?

A

Restructuring existing code without changing its external behavior.

23
Q

How are ES Modules different from CommonJS modules?

A

ES Modules are imported statically and more often used for browsers where CommonJS modules are imported with functions and commonly used for Node.

24
Q

What kind of modules can Webpack support?

A

Both ES6 and CommonJS.