JavaScript ES6 Flashcards

1
Q

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

A

Code inside curly braces, like a function or if block

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

What does block scope mean?

A

Scoped inside of a code block. Not accessible outside 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

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 allows re-assignment. const does not allow re-assignment.

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 address is immutable, but the object the address refers, too, is not. Therefore the object can be modified unless deep freezed.

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 intend to re-assign the value. Const protects the variable from being re-assigned.

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

${variable_name inside back ticks

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

Assigning properties of an object or elements of an array to individual 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

{ key1, key2, key3 } = 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

[ var1, var2] = 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

destructoring is on the left side of the = sign, creating is on the right side

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

What are the three states a Promise can be in?

A

pending, fulfilled, rejected

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

How do you handle the fulfillment of a Promise?

A

then clause

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

How do you handle the rejection of a Promise?

A

catch clause

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

What is “syntactic sugar”?

A

Syntax designed to make code easier to read or express

17
Q

What is the typeof an ES6 class?

A

function

18
Q

Describe ES6 class syntax.

A

class keyword followed by name and braces. prototype methods in the class body.

19
Q

What is “refactoring”?

A

process of restructuring code without changing its functionality to improve readability and maintainability

20
Q

How are ES Modules different from CommonJS modules?

A

ES Modules can be statically analyzed (for static checking, optimization), better support for cyclic dependencies

21
Q

What kind of modules can Webpack support?

A

ECMAScript modules, CommonJS modules, AMD modules, Assets, WebAssembly modules

22
Q

What must the return value of myFunction be if the following expression is possible?
myFunction()();

A

return is a function

23
Q
What does this code do?
const wrap = value => () => value;
A

return value function

24
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

when it’s defined

25
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

closure