ES6 Flashcards

1
Q

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

A

Piece of code that is to be ran.

Function code block
Conditional code block
Loop 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

The area inside a code block.

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

What is a block scoped variable?

A

Exists inside code block only

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, not attached to the global object
Can be reassigned

const is:
immutable, read-only (cannot be changed but properties can be altered).
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

Push works because you’re not reassigning the data type of the array is but changing contents of the 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 const unless you cant.

If variable will get reassigned use let.

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

Backticks ``
Strings
Expressions (using ${JavaScript expression}
- Any expression that has a value could be used

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

What is ‘string interpolation’?

A

The substitution of a string using the values of expressions and variables

${expressionName}

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

What is destructuring, conceptually?

A

A way to extract values from declared arrays and objects

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
variable keyword
curly braces
property names
variable names (if not using property names)
equal sign
object 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

const [x, y, z] = arrayName

variable keyword
brackets
element names in array
variable name (if not using element name)
equal sign
array 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 curly braces/brackets on the left side and object/array name on right side

Creating curly braces/brackets on the right side and object/array name on left 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

(p1, p2, …, pn) => expression;

Variable (optional dependent on use case)
Parameters in parentheses (optional)
Arrow function
Code block or expression

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

Without curly brace return is implied

With curly brace return statement is needed

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

How is the value of this determined with an arrow function?

A

With whatever this was assigned to

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

What is a Promise?

A

A proxy value that isn’t known when the promise is made

17
Q

What are the three states a Promise can be in?

A

Pending: the initial state, neither fulfilled or rejected
Fulfilled: a successful operation
Rejected: a failed operation

18
Q

How do you write a then method?

A

const promiseName = return of promise function

promiseName.then(parameterName => {
console.log(parameterName);
});

parameterName is defined as the fulfillment of the promise

19
Q

How do you write a catch method?

A

const promiseName = return of promise function

promiseName.catch(error => {
console.error(error.message);
});

error is defined as what happens when the promise is rejected

20
Q

How do you handle a fulfilled promise?

A

Using a then method and passing a callback

which contains the fulfilled argument

21
Q

How do you handle a rejected promise?

A

Using the catch method and using a callback function with the rejected argument

22
Q

What is Array.prototype.filter useful for?

A

Creating a new array that has values that pass the test implemented by the function.

23
Q

How to write an Array.prototype.filter()?

A
const filteredArray = array.filter(predicate => {
code block
});
24
Q

What is Array.prototype.map useful for?

A

A new array with each element from the array being the result of the function being used.

25
Q

How to write Array.prototype.map?

A
const mappedArrayName = array.map(arrayValue => {
code block
});
26
Q

If you didn’t have the map method how would you write it?

A
function map(array, transform) {
   const mapped = [ ];
   for (let i = 0; i < array.length; i++) {
      mapped.push(transform(array[i]));
   }
   return mapped;
}
27
Q

Why are for loops faster than methods?

A

Methods have to go through stack of an event loop

28
Q

If you didn’t have filter method how would you have to write it?

A
function filter(array, predicate) {
   const filtered = [ ];   
   for (let i = 0; i < array.length; i++) {
      if (predicate(array[i])) {
         filtered.push(array[i]);
      }
   }
   return filtered;
}
29
Q

What is Array.prototype.reduce useful for?

A

To combine elements in an array into a single value

30
Q

How to write an Array.prototype.reduce?

A
const reducedArray = array.reduce([previousValue, currentValue  => {
codeblock
});

Name previousValue the return value of what your variable will be named
Name currentValue an element from your array

31
Q

If reduce method did not exist how would you write a raw function of it?

A
function reduce(array, combine, initialValue) {
   var i = 0;
   if (arguments.length === 2) {

}
}

32
Q

What is “syntactic sugar”?

A

Syntax that makes the programming language easier to read/express.

33
Q

What is typeof an ES6 class?

A

Function

34
Q

Describe ES6 class syntax.

A
class className {
   constructor(constructorName) {
      this.constructorName = constructorName;
   }
   getConstructorName( ) {
      return this.constructorName;
   }
}
  • Constructor part isn’t necessary
35
Q

What is “refactoring”?

A

Process of restructuring existing code without changing the original functionality. This in turn improves:

  • Readability
  • Reduces complexity
  • Faster performance
  • Less memory usage
36
Q

How are ES modules different from CommonJS modules?

A

ES modules are different because they use export with the defined javascript expression name, export default, or export with export names in curly brace.

Does not support require for imports or module.exports

ES is officially a part of JavaScript and CommonJS isn’t. However webpacks supports both

37
Q

What kind of modules can Webpack support?

A
ECMAScript
CommonJS
AMD
Assets
WebAssembly