ES6 (JavaScript) Flashcards

1
Q

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

A

A group statements between curly braces.

i.e., a function code block or a if statement code block.

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

What does block scope mean?

A

Block scope restricts the access to a variable to only within its code 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

Blocked scope.

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

Variables declared using let are mutable (can be reassigned).

Variables declared using const are immutable (cannot be reassigned).

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 creates a variable that is read-only.

The array assigned to a const variable can be modified, but the const variable itself cannot be assigned a new array or other 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

Whether the developer intends to reassign a variable.

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

A string or (optional) JavaScript expressions in between 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 a 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

A (alternative) way to assign properties of an object to variables or assign elements of an array 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

The const keyword followed by curly braces. Inside the curly braces is the property of an object and variable name separated by a colon. After the curly brace is an assignment operator followed by the name of the object and semicolon.

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

The const keyword followed by square brackets. Inside the square brackets are variable names separated by commas. After the square brackets is an assignment operator followed by the name of the array and semicolon.

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

Objects use curly braces and arrays use square brackets.

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 separated by commas inside parenthesis (if any/two or more) followed by an arrow. After the arrow, there can either be an expression or an arrow function body that has a return operator then a semicolon.

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

Without curly braces, the arrow function returns the result of an expression (implicit return expression) instead of returning a value.

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

The value of this determined by it’s surrounding code block.

The value of this is determined when the arrow function is defined.

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: The operation was completed successfully.

Rejected: The operation failed.

17
Q

How do you handle the fulfillment of a Promise?

A

By calling the .then() method on the promise object.

18
Q

How do you handle the rejection of a Promise?

A

By calling the .catch() method of the promise object.

19
Q

What is “syntactic sugar”?

A

Code syntax that is written in a way that is easy to read or express clearly.

20
Q

What is the typeof an ES6 class?

A

The ‘function’ data type.

21
Q

Describe ES6 class syntax.

A

The class keyword followed by the name of the class (capitalized) and the code block.

Within the code block, there is a constructor definition and optional method definitions separated by a line space.

22
Q

What is “refactoring”?

A

The process of improving the design or implementation of existing code while preserving functionality.

23
Q

How are ES Modules different from CommonJS modules?

A

ES Modules (Official)
- Files are imported using the ‘import’ statement.
- Files are exported using the ‘export’ statement.

CommonJS Modules (Community)
- Files are imported using ‘require’ function.
- Files are exported using the ‘exports’ property.

24
Q

What kind of modules can Webpack support?

A

Both ES and CommonJS modules are supported.

25
Q

What does fetch() return?

A

A promise that resolves to a response object.

26
Q

What is the default request method used by fetch()?

A

The GET request method.

27
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

By setting the method property to the desired request method in the options parameter of the fetch method call.