ES6 Flashcards

1
Q

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

A

Surrounded by brackets with code written inside. Functions, loops, if conditionals

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

What does block scope mean?

A

Only available within that block

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

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

We are not reassigning the value

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

You let if you need the value to change (reassigned) and const if the value will always be the same.

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

Using backticks around the string and a dollar sign with curly brace around the variable

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

What is “string interpolation”?

A

Substituting part of a string with variables.

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

What is destructuring, conceptually?

A

To take pieces of a more complex structure (elements from array, prop from obj) and assign them to variables. Assigning properties of an object or an array 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

const object with key value pairs assigned to a variable

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 with square brackets with variable names with an assignment operator and the array it’s coming from

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

Objects or array is on the left of the assignment operator for destructuring while objects or array is on the right of the assignment operator when creating an object/array literal

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

Variable keyword, var name, parameters (necessary if zero parameter, optional if one parameter and necessary if more than one parameter), arrow, curly braces (only if a statement)

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

You can only have one line of code. Has to be an 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

Is based on when the arrow function is defined. The value of ‘this’ in its parent code block. If the parent is an arrow function as well, it keeps going up.

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, rejected

17
Q

How do you handle the fulfillment of a Promise?

A

then()

18
Q

How do you handle the rejection of a Promise?

A

catch()

19
Q

What is Array.prototype.filter useful for?

A

To find things within an array

20
Q

What is Array.prototype.map useful for?

A

To apply a transformation to each element in an array

21
Q

What is Array.prototype.reduce useful for?

A

To getting a single value from combining elements from an array

22
Q

What is “syntactic sugar”?

A

Syntax within a programming language that makes things easier to read or to express.

23
Q

What is the typeof an ES6 class?

A

Function

24
Q

Describe ES6 class syntax

A

Keyword class followed by the name of the class with a code block. A constructor in the function (optional) with methods below it.

25
Q

What is “refactoring”?

A

The process of restructuring existing code without changing its external behavior

26
Q

How are ES Modules different from CommonJS modules?

A

ES module syntax is more compact and can export multiple things. Keywords are different - import/export vs require. Static (ES Module - it will look at the code and remove any unused portions) vs dynamic (CommonJS module). ES6 is ‘official’

27
Q

What kind of modules can Webpack support?

A

ECMAScript, CommonJS and AMD modules.