ES6 Flashcards

1
Q

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

A

Code blocks are a group of statements that need to be executed.
Code blocks are defined using curly braces., such as functions, if/else statements, loops.

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

What does block scope mean?

A

The variable defined within the block cannot be accessed outside the block that it was declared in.

also makes a shadow copy of variable that was declared outside 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 const and let are declared as block - scope.

Var variables are not block-scope they are function 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

Let is mutable meaning you can change their values anytime you want.
Const is immutable meaning you can’t reassign them to different values.
You CANNOt reassign a const variable.

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

Even though the variable is a constant, you can change the value of its property.

However, you cannot reassign a different value to the constant.

The values inside the const array can be change, it can add new items to const arrays but it cannot reference to a new 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

Use let when youre sure that the value of the variable will change.
otherwise 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

Template literals are enclosed by backtick (`) characters instead of double or single quotes.

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

What is “string interpolation”?

A

String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.

using template literals you can substitute variables or expressions into a string using the special block which its syntax is ${expression}.

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

What is destructuring, conceptually?

A

it lets you extract data from objects or arrays and assigning them to different variables.

Object destructuring assigns the properties of an object to variables with the same names by default.

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

const { property1, property2 } = obj;

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

const [ property1, property2] = 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

Object destructuring uses curly braces while arrays use 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

const varName = (param1, param2) => {whatever statements that need to be executed in the 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

it returns the result of the expression.

the return is implied if theyres no curly braces, meaning theres only one statement in the code block.

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

With arrow functions the this keyword always represents the object that defined the arrow function.
it takes the this from the enclosing function. it is determined when an arrow function is defined.
gets its this from its surrounding function.
regular functions gets value of this at call time while arrow functions gets value of this at definition 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: 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

Promise.prototype.then() or the then( ) method.

returns a fulfilled promise.

18
Q

How do you handle the rejection of a Promise?

A

Promise.prototype.catch() or catch( ) method.
returns a promise and deals with rejected cases only.
The catch method is used for error handling in promise composition

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. 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 className { } - Class Body

class Person {
    constructor(name) {
        this.name = name;
    }
getName() {
    return this.name;
} }
let name = new Person ('Tim Davis')
console.log(name);
22
Q

What is “refactoring”?

A

code refactoring is the process of restructuring existing computer code—changing the factoring—without changing its external behavior.
Refactoring is intended to improve the design, structure, and/or implementation of the software (its non-functional attributes), while preserving its functionality.
Potential advantages of refactoring may include improved code readability and reduced complexity; these can improve the source code’s maintainability and create a simpler, cleaner, or more expressive internal architecture or object model to improve extensibility.

23
Q

How are ES Modules different from CommonJS modules?

A

ES Modules are the standard for JavaScript, While CommonJS is the default in Node.Js
They have different syntax Import / Export vs require( ) & module.exports.
ES Module syntax is much more readable than require( ).

24
Q

What kind of modules can Webpack support?

A

ECMAScript (ES) Modules, CommonJS Modules, and AMD Modules