ES6 Flashcards

1
Q

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

A

Code block is code that is within 1 set of curly braces
I.e. function code block, for loop code block, 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 means what variables are available within the scope of the curly braces of the 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

The scope of let is within the code block only. It can be declare outside the code block and accessed within a code block to be changed, but outside of the code block, it cannot access whatever was inside the code block
The scope of const is block scoped also and cannot be redeclared
Var are function scoped, can be accessed outside of block 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

The value of let is mutable and can be reassigned, etc
The value of const is immutable/cannot be reassigned and is a read-only reference to the value, with the exception of its property values, which can be changed and/or 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 the array object is not being reassigned, but the properties aka elements can be changed and thus pushed and popped off.

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

Depends on how you want to use the variable, if the value needs to be changed or stay the same

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

It uses backticks (This is a template literal) to store the string rather than single or double quotes
The variables inside the backticks would be written as ${variableName}

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

What is “string interpolation”?

A

Template literals can have substitutions within the backticks which embed variables and expressions in strings that JavaScript automatically replaces with their values without having to concatenate

I.e. const firstName = ‘John’,
const lastName = ‘Doe’;

  const greeting = `Hi ${firstName}, ${lastName}`;
  console.log(greeting); // Hi John, Doe
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is destructuring, conceptually?

A

Getting multiple variables from array or object elements and assigning them to another 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

There’s a variable in front like const, var, let and curly braces and properties you want to assign, end curly brace, = assignment operator and the object name
const { propertyName: value, propertyName: value, propertyName: value, } = objectName;
Don’t need the colon and value name if the variable is the same name as the value 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

There’s a variable in front like const, var, let and square brackets and name of variable to be assigned at the location of the array, square bracket = assignment operator and the array name
const [book3, book4, book5] = library;
Can you comma to skip the order of the array to get to another spot
I.e. const [, , , book6] = library;

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 has curly and square brackets on the left side of the = assignment operator
Creating has curly and square brackets on the right side of the = assignment operator

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

Const variableName = (parameter1, parameter2) => {expression with the parameters};
Parameter1 => {normal code block} or return expression
*no parameter () =>
If no parameter, parentheses, if one parameter, parentheses optional, if multiple parameters, parentheses needed
(… args) => expression to define an arrow function
(…args) => { statements} to define an arrow function with multiple 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

You don’t have to type return for the return expression, it will implicitly return the expression
Also, JavaScript can’t tell the difference between the expression in the block and object if there’s an object in the expression

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 defined by the surrounding code block
The arrow function captures the this value of the enclosing context instead of “creating” its own this context if the arrow function were not there
The value of this is defined at definition time during arrow 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

Pending
Fulfilled
Rejected

17
Q

How do you handle the fulfillment of a Promise?

A

Promise.then() method

18
Q

How do you handle the rejection of a Promise?

A

Promise.catch() method

19
Q

What is “syntactic sugar”?

A

Code that is easier to read for humans, or easier to write
“Sweetening” of the code you’re writing, or more ergonomic way of writing

20
Q

What is the typeof an ES6 class?

A

It’s a syntactic sugar for the constructor function

21
Q

Describe ES6 class syntax.

A

Class [name] {
constructor(parameters) {
This.parameter1 = [value];
This.parameter2 = [value];
}
prototypeMethodName {
[do whatever the prototype method will do]
}
}

22
Q

What is “refactoring”?

A

Restructuring code to make it easier to read, modify, test, read
** behavior must be exactly the same

23
Q

How are ES Modules different from CommonJS modules?

A

The ES modules syntax is shorter and more concise
ES Modules
Import / export syntax
Officially part of ECMAScript, so always supported
CommonJS
.require and module.export syntax\
Not official, community effort (browsers will never support them and need webpack to make them work)

24
Q

What kind of modules can Webpack support?

A

CommonJS, ECMAScript modules, AMD(Asynchronous Module Definition)