ES6 Flashcards

1
Q

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

A

A declaration that is used to group zero or more statements, in curly braces
An example: function, for loops, conditionals, etc.

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

What does block scope mean?

A

If a variable is declared inside a block scope, it is locally scoped to 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 with const or let?

A

Block-scoped.

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 variables are mutable, while const are not. Cannot be reassigned with different values
Const ensures that the variable it creates is read-only
But you can change the value of a property of a const variable

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 value is still an array, and the elements of that array aren’t bound to the const of the variable that points to an array
You cannot reassign the array to another array
Array can be mutated, but we haven’t reassigned the name variable.

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 let if you intend to reassign the initialized value of the variable
Use const otherwise(?)
Stick with const until you can’t

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

Backticks instead of quotes

For any expression you want to evaluate = ${expression}

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 the string for the values of variables or expressions.

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

What is destructuring conceptually?

A

Extracting data from arrays, objects into new variables

Take pieces of complex structure, take them out and assign them to 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

Declare a new object with the properties on the left side of colons, assigned to the original object variable.

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

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

A

If the braces/brackets on the right side, it’s destructuring, and opposite is not.

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

What is the syntax for defining an arrow function?

A

const variable name, equals parentheses, equal sign, right arrow, curly braces
- if 1 param, parentheses optional

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

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

A

it has to be an expression

- no if statements, etc.

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

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

A

In an arrow function def, you look outside to the next function definition, you keep going up and looking up, eventually hit a normal ES5 function that was called as a method of an object
Value of this is determined at call time (regular function) - to find value of object left of the dot
Value of this is determined at definition time (with arrow functions)

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