ES6 JavaScript Flashcards

1
Q

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

A

A block of code to be executed denoted by { curly braces }. Code blocks are found inside conditionals, loops, functions

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

What does block scope mean?

A

Any variables declared inside a code block only exist within that 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

both are 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

Const can’t be reassigned, where 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

Because we can mutate the elements of a mutable object like an array or plain object that is assigned to a const variable, and the array/object is not being 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

Use the const keyword when defining a variable that should not be changed - use the let keyword where you intend on changing the value. Prefer const over let.

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

What is destructuring, conceptually?

A

Destructuring allows to unpack elements from an array and properties from objects and assign each to a variable.

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

What is the syntax for Object destructuring?

A

const { propertykeys: variableNames} = objectName
OR
const { propertyKeys, …} = objectName (if variable name = property name)

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

What is the syntax for Array destructuring?

A

const [ variableNames, … ] = arrayName

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

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

A

object/array literal names are on the left when creating, on the right when destructuring

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

A Template Literal uses backticks instead of single or double quotes. To insert a variable write a JavaScript Expression – ${variable}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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
13
Q

What is the syntax for defining an arrow function?

A

cont variable = (param1, param2…) = > { 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

If there are no curly braces there needs to be an expression following the arrow (rather than a statement) and the value of the expression is returned automatically (without return statement).

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

An arrow function captures the This value of the enclosing context instead of creating its own this context. the This is determined at definition time (rather than at call time like regular functions)

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
  1. Pending: initial state, neither fulfilled nor rejected.
  2. Fulfilled: meaning that the operation was completed successfully.
  3. Rejected: meaning that the operation failed.
17
Q

How do you handle the fulfillment of a Promise?

A

.then ( ) method

.then (onFulfilledCallback [, onRejectedCallback] )

18
Q

How do you handle the rejection of a Promise?

A

.catch( ) method OR .then( ) method

.catch (onRejectedCallback ) OR .then(fulfilledCallback, rejectedCallback )

19
Q

What is “syntactic sugar”?

A

Syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express. Does not change the behavior of the code.

20
Q

What is the typeof an ES6 class?

A

function

21
Q

Describe ES6 class syntax.

A

Use the class keyword followed by the name of the class, followed by curly braces. Inside the curly braces you can include an optional constructor function where you can add the properties of an instance and you can also add optional prototype method definitions.

22
Q

What is “refactoring”?

A

The process of restructuring existing computer code—changing the factoring—without changing its behavior.

Refactoring is intended to improve the design, structure, and/or implementation of the software, while preserving its functionality.