ES6 Flashcards

1
Q

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

A

-Grouped zero or more statements within curly braces

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

What does block scope mean?

A

-A block scope is the area within if, switch conditions or for and while loops.

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

-Those variables exist only within the corresponding block.

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

-Variable declared by let are mutable but variables declared by const 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
  • The const keyword ensures that the variable it creates is read-only
  • However, it doesn’t mean that the actual value to which the const variable reference is immutable
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

-For read-only variables, use const

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
  • Use backticks instead of single or double quotes

- To substitute a variable and an expression, use this block: ${variable_name}

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

What is “string interpolation”?

A

-String interpolation allow you to embed variables and expressions in a string. The JavaScript engine will automatically replace these variables and expressions with their values.

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

What is destructuring, conceptually?

A

-Unpacking values from objects and arrays into 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
  • Variable declaration
  • Curly braces
  • The identifier before the colon (:) is the property of the object and the identifier after the colon is the variable
  • Equal sign and object name
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
  • Variable declaration
  • Square brackets with variable names separated by commas
  • Equal sign and object name
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
  • When creating object/array literals, we assign the object to the variable
  • When destructuring, we assign the object to the variable
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
  • Use the (…args) => expression; to define an arrow function
  • Use the (…args) => { statements } to define an arrow function that has multiple statements
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

-If there are no curly braces, the expression is automatically returned from the arrow function

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

-An arrow function captures the this value of the enclosing context instead of creating its own this context

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
  • .then()

- .catch()

19
Q

What is “syntactic sugar”?

A

-In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express.

20
Q

What is the typeof an ES6 class?

A

-Function

21
Q

Describe ES6 class syntax.

A
  • class keyword, name of class
  • Constructor keyword with argument followed by code block where properties of an instance are initialized
  • function definition without the function keyword
22
Q

What is “refactoring”?

A

-Process of restructuring existing code without changing its external behavior