JavaScript ES6 Flashcards

1
Q

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

A

block of code inside 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

only accessible inside the 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 variables

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

const = x change
let = can change

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

not reassigning it, just changing its 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

if reassignment is needed use let /
otherwise 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

using backticks ` `

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
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
9
Q

What is destructuring, conceptually?

A

taking properties of object out and assigning 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

const book1 = { title: ‘Goodnight Punpun’, author: ‘Inio Asano’, libraryID: 3353 };

const { title, author, libraryID } = book1;
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 [x, y, z] = library;

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

creating : variable left hand side

destructuring: variable right hand side

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

parameters => expression/return 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

returns the result of the 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

Unlike an anonymous function, 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

const bar = (n) => 2 * n

A

same as
function bar (n) {
return 2 * n
};

17
Q

What are the three states a Promise can be in?

A

pending: initial state, neither fulfilled nor rejected.

fulfilled: meaning that the operation was completed successfully.

rejected: meaning that the operation failed.

18
Q

How do you handle the fulfillment of a Promise?

A

.then()

19
Q

How do you handle the rejection of a Promise?

A

.catch()

20
Q

What is “syntactic sugar”?

A

Designed to make things easier to read or to express. It makes the language “sweeter” for human use: things can be expressed more clearly, more concisely, or in an alternative style that some may prefer.

21
Q

What is the typeof an ES6 class?

A

Object

22
Q

Describe ES6 class syntax.

A

class Person {
constructor(name) {
this.name = name;
}
getName() {
return this.name;
}
}

23
Q

What is “refactoring”?

A

restructuring the format to make it more readable