ES6 Flashcards

1
Q

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

A

Code surrounded by curly brackets. If statements, for loops, function definitions

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

What does block scope mean?

A

Exists within curly braces {}

The scope is based on the container 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

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

Let values can be resigned while const can’t be resigned

const is a ‘read-only’ reference to a value

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

Objects are mutable, we are not reassigning the const variable, just updating the array

The value of ‘const’ variable is mutable; you can change the value of the property.

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 variable is reassigned, use let.

if variable doesn’t reassigned, use const

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

Use backticks `

Backticks beginning and end of template literal; ${} to embed in literal “${expresstion}”

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

What is “string interpolation”?

A

Substitute result of expressions into a string; using ${} syntax

Replace variables and expressions in a string through substitution in template literals using a special block.

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

What is destructuring, conceptually?

A

Assigning properties of an object to a variable (different or same name).

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/const/var {
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/const/var [variable1, variable2] = 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

Brackets on left hand side of ‘=’ for destructuring; creating will be on right hand side

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
let add = (x,y) => x + y;
let add = (x, y) => { return x + y; };

Use parenthesis for parameters if 0 and more than 1 parameters. 1 parameter does not need it; use curly braces if more than one line of code

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 need a return statement

if you use an expression in the body of an arrow function, you don’t need to use the curly braces. However, if you use a statement, you must wrap it inside a pair of curly braces

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 function, ‘this’ is defined at definition time, not call time.

‘this’ goes to global scope or first non arrow function

arrow function captures the ‘this’ value of the enclosing context instead of creating its own this context.

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: meaning that the operation was completed successfully.
rejected: meaning that the operation failed.

17
Q

How do you handle the fulfillment of a Promise?

A

then() method

const promise1 = new Promise((resolve, reject) => {
  resolve('Success!');
});

promise1.then((value) => {
console.log(value);
// expected output: “Success!”
});

18
Q

How do you handle the rejection of a Promise?

A

catch() method

const promise1 = new Promise((resolve, reject) => {
  throw 'Uh-oh!';
});

promise1.catch((error) => {
console.error(error);
});
// expected output: Uh-oh!

19
Q

What is “syntactic sugar”?

A

Syntax to make code cleaner and “easier” to read and understand

Syntax within a programming language that is 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 prefer.

20
Q

What is the ‘typeof’ an ES6 class?

A

Function

21
Q

Describe ES6 class syntax.

A
class Person {
    constructor(name) {
        this.name = name;
    }
    getName() {
        return this.name;
    }
}
22
Q

What is “refactoring”?

A

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

23
Q

How are ES Modules different from CommonJS modules?

A

If not default export, use curly bracket from module importing, if exporting multiple functions

CommonJS: require() and module.exports
ES Modules: export [default] function myFunction{ };
import myFunction from ‘function.js’;
import {myFunction1, myFunction2} from ‘function.js’;
import * as function from ‘./function.js’

24
Q

What kind of modules can Webpack support?

A

ECMAScript modules, CommonJS modules, AMD modules, Assets, WebAssembly modules.