es6 Flashcards

1
Q

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

A

A block of code within the curly braces. Function, while, for, if else.

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

What does block scope mean?

A

An area within the block where variables can be referenced.

Variables are only accessible within 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

let = block-scoped (within any code block { }. Ex. if (xx) {} for(xx) {})
const = block-scoped
var = function-scoped - if there is no function it is defined in, it’s globally 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

Const can’t be reassigned. The values of whatever it is assigned to can be manipulated or changed but you cannot reassign it.

Let can 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 value with the array is mutable.

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 variable declaration to use?

A

If the variable is not going to be reassigned, use ‘const’.
If the variable will be reassigned then use ‘let’.

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

Template literals use backticks rather than single or double quotes and commonly use string interpolation for JavaScript expressions or variables: ${variable} ${1 + 1}

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

What is string interpolation?

A

A process where variables and expressions are embedded in a string. The variable/expression must be placed in a space block as follows: ${variable_name}

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

What is destructuring conceptually?

A

Taking the values within an object or an array and assigning them to a variable.

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

let { property1:variable1, property2: variable2} = object

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

let [index1, index2] = 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

Destructuring: the variable name goes on the right of the assign operator.
let/const {} or [] = variable name
Creating: variable name goes on the left of the assign operator
variable = {} or []

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) => {}

If there is only 1 parameter the parentheses are not needed. If the return is a simple expression, brackets and return keyword can be omitted. Brackets and return keyword are needed for code block if it’s multiline statements.

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 becomes a return

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

Arrow functions: the value of this is determined at definition time.
Regular functions: the value of this is determined at call time.

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: intitial state, neither fulfilled nor rejected.
Fulfilled: The operation was completed successfully.
Rejected: Meaning that the operation failed.

17
Q

How do you handle the fulfillment of a promise?

A

Use .then() method.

18
Q

How do you hand the rejection of a promise?

A

Use .catch() method.

19
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 lrefer.

20
Q

What is “refactoring”?

A

The process of restructuring existing code without changing its external behavior. Refactoring is intended to improve the design, structure and implementation of the software.

21
Q

How are ES6 modules different from commonJS modules?

A

CommonJS uses require() method to import and module.export to export.

ES6 modules use import and export statements.

22
Q

What kind of modules can Webpack support?

A

ECMAScript modules, CommonJS modules, AMD modules.

23
Q

What is temporal dead zone? (TDZ)

A

When you try to use a variable before its declared.

24
Q

Function declarations are hoisted to the top of script so you can call functions before where they’re defined.

A