ES6 const & let, template literals, destructuring, and arrow functions Flashcards

1
Q

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

A

A code block is a chunk of code inside curly braces

if (conditions) { //code block here }

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

What does a block scope mean?

A

Code in a code block can only be referenced by code that is in the code 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 scoped as opposed to function 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 is mutable

const values cannot be re-assigned, they are immutable

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

Variables are objects, objects are mutable

You are updated the index value of an array, but not re-assigning the value of the variable itself

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 should use const when the value of the variable isn’t going to be updated

You should use let when the value of the variable is going to be updated

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 name = String content here

Surround a string with backticks

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

What is string interpolation?

A

String interpolation allows you to embed variables and expressions in the string.

JavaScript will automatically replace these variables and expressions by their values

${variable}

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

What is destructing, conceptually?

A

Taking either properties of an object or indexes of an array to separate them to create specific 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 { property, property2, property3 } = objectName

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 [ variable, variable2, variable3 ] = arrayName

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

If the brackets are on the left side of the assignment operator, you are destructuring.

If the brackets are on the right side of the assignment operator, you are creating.

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

Without curly braces, you can only have a return on to the right of the arrow.

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

With an arrow function, it is determined at definition time

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

What is the syntax for defining an arrow function?

A

() => line of argument

() => { code block }

(para1, para2) => 1 line of argument

(para1, para2) => { code block }

para => 1 line of argument

para => { code block }

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