ES6 JS Flashcards

1
Q

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

A

without {} the result will be auto returned

with {} you have to add return mannuly

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

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

A

when the function defined

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

How is the value of this determined within a normal function?

A

call time

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

What is destructuring, conceptually?

A

Destructuring is a convenient way of extracting multiple values from data stored in (possibly nested) objects and Arrays.

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

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

A

Function in if, for, while loop (code with {})

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

What does block scope mean?

A

the variable outside the block can be use in block, but the variable in block cannot be use in outside

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

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

A

they can’t scope to outside

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

What is the difference between let and const?

A

const cannot change (ex: minute per hour, book name…)

let can be change

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

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

A

because it’s change the property of object, not abject

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

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

A

use let when the value probably change in the futures , const for the value that gonna always be the same

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

What is the syntax for writing a template literal?

A

xxxx

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

What is “string interpolation”?

A

a string contains varible and algorithms.
xxxx${xx}xx

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

What is the syntax for Object destructuring?

A

const { title, author, libraryID } = book1;
const { title: title2, author: author2, libraryID: libraryID2 } = book2;

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

What is the syntax for Array destructuring?

A

const [book3, book4, book5] = library;

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

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

A

object is {} array is []

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

What is the syntax for defining an arrow function?

A

xxx = (parameters1, parameters2) => xxx
if only one expression, {} is not need.
multiple lines expression needs be surround by {}

17
Q

How do you handle the fulfillment of a Promise?

A

promise.then()

18
Q

How do you handle the rejection of a Promise?

A

promise.catch()

19
Q

error

A

error is object, has message and other key>
console.log() call the
console.dir() call the
console.error() make it to red error

20
Q

reduce(accumulator, currentValue)

A

can make accumulator an Array of functions to process currentValue multiple times by the reduce function