ES6 Flashcards

1
Q

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

A

A series of grouped code statements in curly braces. The body of a for loop, while loop, if statement, function.

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

What does block scope mean?

A

Variables declared within a containing code block are only accessible within that containing 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 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

A let variable can be reassigned another value after declaration
A constant can not be reassigned another value after declaration

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

Although a constant can not be reassigned another value, if it points to an array, that array can be manipulated. Since the constant still points to the same array, reassignment is not occurring.

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 you plan on never reassigning another value, then declare a constant.
If you plan on reassigning another value, then declare a let variable.

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

What is destructuring, conceptually?

A
  • breaking up the structure

- in JavaScript, it is a shortcut for assigning array values and object properties to variables

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

What is the syntax for Object destructuring?

A
variable keyword followed by opening curly brace, property name (with optional colon and variable name), closing curly brace, assignment operator, and object name
let {
   firstName: fname, 
   lastName: lname
} = person;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the syntax for Array destructuring?

A

variable keyword followed by opening bracket, variable names in indexed order, closing bracket, assignment operator, array name
let [x, y, z] = arrayName

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

How can you tell the difference between destructuring and creating Object/Array literals?

A

In destructuring, [] and {} are on the left hand side of the assignment operator and the name of the array or object is on the right hand side

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

What is the syntax for writing a template literal?

A

backtick, string, placeholder expressions, backtick

Fifteen is ${a + b} and not ${2 * a + b}.

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

What is “string interpolation”?

A

replacing placeholders with values in a template literal

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

( ) => { }
parameter (parenthesis if more than one parameter), followed by equal sign/arrow, followed by expression (optional curly braces/ return statement)

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

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

It comes from the outer scope of its container in its definition, since it does not have its own reference to ‘this’ at call time like other functions

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

What is Array.prototype.filter useful for?

A

filtering an array into another array

17
Q

What is Array.prototype.map useful for?

A

changing each element of an array, and putting those elements in a new array

18
Q

What is Array.prototype.reduce useful for?

A

combining each element of an array into one element

19
Q

What is “syntactic sugar”?

A

syntax which is easier to read but doesn’t change functionality

20
Q

What is the typeof an ES6 class?

A

function

21
Q

Describe ES6 class syntax.

A
class className {
   constructor(parameter) {
      this.parameter = parameter
   }
   method() {
   }
}
22
Q

What is “refactoring”?

A

restructuring code without altering its behavior

23
Q

What is Webpack?

A

a module bundler for JavaScript applications

24
Q

How do you add a devDependency to a package?

A

npm install –save-dev

25
Q

What is an NPM script?

A

scripts (command line commands) in package.json that run at certain times of production

26
Q

How do you execute Webpack with npm run?

A

npm run

27
Q

How are ES Modules different from CommonJS modules?

A

ES Modules use import __ from ‘path’ and export default

CommonJS Modules use require(‘path’) and module.exports =

28
Q

What kind of modules can Webpack support?

A

both EcmaScript and CommonJS and AMD modules

29
Q

default export

A

can import without curly braces, and can name whatever you want

30
Q

named exports

A

{} are needed and need to import by name

31
Q

What is Babel?

A

toolchain to convert ECMAScript 2015 code into a backwards compatible version of JavaScript

32
Q

What is a Plug-in?

A

component that adds a feature to an existing program

33
Q

What is a Webpack loader?

A

a transformation applied to the source code of a module (can transform files from one language to Javascript)

34
Q

How can you make Babel and Webpack work together?

A

install babel loader