ES6 Flashcards

1
Q

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

A

Code blocks are denoted by curly braces. Usually for an if statement, if else statement, for loop, do while loop, while loop, and try catch

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 refers to the variable thats declared can only exist within that block only.

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

The scope of const and let are both blocked-scope variables.

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

The difference is that let is mutable while const is a read-only reference.

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 .push() doesn’t change the variable from an array to another array or something else. It only adds elements inside that array.

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 a variable is not going to need changing, const should be used. If the variable may need its value updated, let is the right way to declare.

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

The syntax for writing template literal starts with backticks ` and ends with backticks `. Similar to quotes and double quotes.

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

What is “string interpolation”?

A

To replace variables and expressions with their values within a string.

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

What is destructuring, conceptually?

A

Destructing allows properties or elements inside an array to be assigned to a variable in a quicker way. To be able to pull out what is needed from an entire data structure.

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

Declare a variable followed by the curly brace. Property names are assigned to variables with the colon sign in between. Followed by a closing curly brace. and that whole code block is assigned to a variable name.

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

Declare a variable followed by the opening square bracket. Inside are variable names in place of the each object or element in the array. Followed by a closing square bracket and assigned to a variable name.

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 would have the variable declaration but no variable name yet and the variable name is defined at the end. Creating object and array literals involve having the variable name in the beginning before the curly or 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

Instead of using the function keyword, there is just the parameters or empty parameter followed by equal sign and the greater than ankle bracket followed by the code block that runs for that function. The code is implied to return the value unless there is curly brackets then the keyword return needs to be used.

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

The keyword return is implied for the body. If there are multiple expressions to compute, then the return won’t occur.

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 is determined at the time 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, Fulfilled, Rejected

17
Q

How do you handle the fulfillment of a Promise?

A

by using the then() method to have a callback function take action once its fulfilled.

18
Q

How do you handle the rejection of a Promise?

A

by using the then() method or the catch() method to handle the rejection.

19
Q

What is “syntactic sugar”?

A

Syntax that is within a programming language that is designed to make things more easy to read. The sweeter it is for humans, the more clear/concise it is.

20
Q

What is the typeof an ES6 class?

A

ES6 class is a function when checked by typeof. It isn’t recognized as an object.

21
Q

Describe ES6 class syntax.

A

.

22
Q

What is “refactoring”?

A

Refactoring is to update the code but keep the same functionality.

23
Q

How are ES Modules different from CommonJS modules?

A

.

24
Q

What kind of modules can Webpack support?

A

es6 module, commonjs, amd

25
Q

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

A

The return value must be a function in order to be able to call that as well.

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

An anonymous function with a parameter of value is being assigned to the variable wrap. Within the anonymous function’s code block is another anonymous function with no parameters that returns value.

27
Q

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

A

A function’s scope is determined when it is defined.

28
Q

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

A

Closures allow functions to remember values from their surroundings because it forces the garbage disposal to not delete that variable.