ES6 Flashcards

1
Q

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

A
  1. Portions of code denoted by curly braces {}.
  2. Some examples are if/else, for, 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

Variables declared within that code block can’t be accessed by code outside of the block

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

What is the difference between var and let?

A

Var adds the variable to the property list of the global object (window for browsers) —> let does not.

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

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

A

They’re both block scoped.

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

What is the difference between const and let?

A
  1. Block-scoped variables assigned by const keyword can not be reassigned.
  2. You also have to initialize a value to the variable declared by const —> you don’t have to immediately with let.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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

A

The array is not immutable, it can change. It’s just the variable that stores the array that can’t be changed.

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

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

A

Unless you’re positive you’re going to change the memory pointer, use const.

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

What is the syntax for writing a template literal?

A

Use backticks (string-goes-here)

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

What is string interpolation?

A

The ability to substitute part of the string for the values of variables or expressions

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

What is destructuring, conceptually?

A

Taking an array or object and assigning some OR all values to corresponding variables

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

What is the syntax for Object destructuring?

A

Let { property1: variable1, property2: variable2 } = object

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

What is the syntax for Arrray destructuring?

A

[a, b, c] = [value1, value2, value3] OR let [x, y, z] = getScores( )

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

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

A

The variables are always wrapped in an object / array and the sides are swapped.

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

What is the syntax for defining an arrow function?

A

Const functionName = (parameters) => {code block w/optional return}

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

If an arrow function only has one parameter, we can…

A

Remove the parenthesis entirely

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

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

A

Implicit return—> curly braces need an explicit return

17
Q

What determines the ‘this’ inside of a function created with the function keyword?

A

It’s determined by what is to the left of the dot when the function is called

This is the window object by default —> for methods its the object attached to that method

18
Q

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

A

It’s a ‘lexical’ this —> this is determining by the surrounding scope

19
Q

Before ES6, how did we change the binding of this to be the appropriate object instead of the window?

A

Use the bind method with the ‘this’ passed in as an argument

20
Q

When do we need to be extra cautious about ‘this’?

A

When using callback functions!

21
Q

What are the two ways to fix the binding of this within callback functions?

A
  1. Use the bind keyword
  2. Use arrow functions
22
Q

What are two large differences between defining functions using the function keyword and arrow functions?

A
  1. Function definition also has access to the arguments keyword which allows you to loop through the arguments passed into the function
  2. Arrow functions don’t bind the this —> they take the this from the enclosing scope
23
Q

What are the three states a promise can be in?

A

Pending, fulfilled, rejected

24
Q

How do you handle the fulfillment of a promise?

A

Use .then(firstArgFx)

25
Q

How do you handle the rejection of a promise?

A

Use .then(secondArgCbFx) OR .catch

26
Q

How are ES Modules different from CommonJS modules?

A

CommonJS uses require & module.exports whereas ES modules use import / export.

27
Q

What kind of modules can Webpack support?

A

It natively supports ES modules, CommonJS modules, and AMD modules

28
Q

The two types of ES6 exports are…

A

Default exports (can be assigned any name in import file)

Named exports (have to be assigned same name in import file)

29
Q

Why index.js?

A

We often import things from a lib folder —> create an index.js for that folder and then pull all of the imports from the index.js for that folder