JavaScript ES6 Flashcards

1
Q

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

A

Stuff between curly braces. Functions, loops, conditionals.

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

What does block scope mean?

A

anything declared inside a codeblock, stays inside the codeblock.

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

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

you can reassign a let variable but not 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

the array values can be changed, but the variable cannot be reassigned.

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 you are sure you will not need to reassign a variable, use const, otherwise use let. If you are unsure, use const, and change it later if you find out you do need to reassign it.

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 and ${EXPRESSION}

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

What is “string interpolation”?

A

writing strings with substitutions.

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 arrays, or properties from objects, into distinct 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 { objProperty: newVariable, objProperty: newVariable, objProperty: newVariable, etc } = obj;

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 [newVariable, newVariable, newVariable, etc] = array;

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

The brackets or curly braces come before the assignment operator.

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

let functionName = (params) => { code block };

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

it will return the expression after the =>

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
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: initial state, neither fulfilled nor rejected.
fulfilled: meaning that the operation was completed successfully.
rejected: meaning that the operation failed.

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

.catch

19
Q

What does Array.filter do?

A
20
Q

What should the callback function return?

A

returns a truthy or falsey value and if its truthy, add it to the copy.

21
Q

What is Array.filter useful for?

A
22
Q

What does Array.map do?

A
23
Q

What should the callback function return?

A
24
Q

What is Array.filter useful for?

A
25
Q

What does Array.reduce do?

A

walks through an array and reduces it into a single value.

26
Q

What action should the callback function perform?

A

examine the current element, do a computation to it and add it to the accumulated value.

27
Q

What should the callback function return?

A
28
Q

What is Array.reduce useful for?

A
29
Q

What are JavaScript classes?

A

Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on prototypes but also have some syntax and semantics that are unique to classes.

30
Q

When would you want to use a class?

A

If you have data or functionality to encapsulate.

31
Q

How do you declare a class?

A

using the class keyword
class NameOfClass {
code block
}

32
Q

How do you inherit from another class?

A

using the extends keyword
class NameOfClass extends SuperClass {
code block
}

33
Q

Why would you want to inherit from another class?

A

reuse, extend, and modify the behavior defined in other classes

34
Q

How do you add methods and properties to a class?

A