es6 Flashcards

1
Q

What is a code block? What are some examples?

A

a block of code contained by curly braces - loops, if conditions, functions

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

What does block scope mean?

A
  • the block scoped variable is limited in scope to the block in which it was defined. example:

let x = 10;

if (x = 10) {
let x = 20;
console.log(x); // 20: reference x inside the block
}
console.log(x); // 10: reference x at the beginning of the script

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

variables declared by const keyword cannot 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

The const variable is immutable but the values within the array aren’t immutable

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? (const vs let)

A
  • if the variable will be reassigned, use let

- if the variable is never 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 template literals?

A

let example = ` this is a template literal `;

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

What is “string interpolation”?

A

the ability to substitute part of the string for the values of variables or expressions
- (the big difference between template literals and normal strings is substitution. string interpolation allows you to embed variables and expressions in a string. JS will automatically replace these variables/expressions with their values)

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

what is destructuring, conceptually?

A

makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

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: variable1, property2: variable2,,} = objectName

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 [element1, element2, element3,,] = arrayName

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 the left side of = , destructuring

- if creating object/array, brackets are on the right side of the =

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 funcName = (parameter1, parameter2,…) => { code }

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

When an arrow functions body is left without curly braces, what changes in its functionality?

A
  • nothing changes if you use a single expression in the code block.
  • if you use a statement or multiple lines of code, braces are needed
    (arrow functions dont magically know what or when to return)
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
  • arrow functions establish “this” based on the scope the arrow function is defined within
  • determined at definition time instead of call 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 or rejected
  • fulfilled : meaning that the operation was completed successfully
  • rejected : meaning that the operation failed
17
Q

How do you handle fulfillment of a Promise?

A
  • use the ‘.then’ method
18
Q

How do you handle the rejection of a Promise?

A
  • use the ‘.catch’ method
19
Q

What is “syntactic sugar”?

A
  • syntax within a programming language that is designed to make things easier to read or to express. makes the language “sweeter” for human use
20
Q

Describe ES6 class syntax:

A
  • declare a class followed by a { class body}
  • define 0 or more prototype methods of the class
class Name { 
     constructor(param1, param2,..) {
 Prototype method( ) {}

}

21
Q

What is refactoring?

A
  • restructuring existing code without changing its external behavior
  • to improve the design, structure, and implementation of the software while preserving its functionality
22
Q

How are ES6 modules different from CommonJS modules?

A
  • ES6 module syntax is part of the language, while CommonJS is a community “bolt-on”
  • different syntax (imports/exports instead of require)
  • import/exports are static rather than dynamic
23
Q

What kind of modules can Webpack support?

A
  • EcmaScript Modules (ES6)
  • CommonJS Modules
  • AMD Mdules
  • WebAssembly Modules