ES6 Flashcards

1
Q

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

A

Code blocks are denoted with curly brace brackets. Some examples include function code blocks, conditional statements, loop code blocks.

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 is only accessible within that code block.

Variables declared using var are accessible outside of a code block except for function code blocks

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’ can be reassigned while ‘const’ cannot

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 variable has the same memory address as its value, referring to a certain array. The array is mutable but the location in memory remains constant
The name binding cannot be changed
The array remains constant, not the elements within it

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

Rather than use ‘var’, use ‘const’ or ‘let’. If the variable is going to be changed from its initial value, use ‘let’

usually default to ‘const.’ If there is problems in the future, change to ‘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

backtick $ { } backtick

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

What is “string interpolation?”

A

Substituting parts of a string with the values of variables or expressions

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

What is destructuring, conceptually?

A

Taking the properties of an object and assigning them to multiple variables in one go

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 thing = {
this: 1,
that: 2,
};

const { this, that } = thing;
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 things = [
{this: 1, that 1},
{this: 2, that 2}
]

const [thing2, thing3] = things

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

With destructuring, curly brackets on the left hand side of equal sign
With creating, curly brackets on the right hand side of equal sign

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 1, parameter 2) => {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

The arrow function returns value of the expression of the body without the curly brace (an implicit 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

While regular function syntax will create a new function that creates its own this, arrow functions do not create their own this. Instead, it will be lexically scoped, so it will find the this for the context that it is within
They don’t create their own this binding
Value of this is defined at definition time, not at call time (which is the case for traditional ES5 functions)
If you can’t see where it’s being called, this might be referring to the global window

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

What is a CLI?

A

Command Line Interface

17
Q

What is a GUI?

A

Graphical User Interface

18
Q

Give at least one case for each of the commands used in this exercise.

A
  • man: manual
  • cat: concatenate files
  • ls: list directory contents
  • pwd: print working directory
  • echo: display text
  • touch: change file timestamps
  • mkdir: make directories
  • mv: move files
  • rm: remove files
  • cp: copy files
19
Q

What are 3 virtues of a great programmer?

A

Laziness, impatience, hubris

20
Q

What are the 3 states a Promise can be in?

A
  • Pending- promise is created, promise hasn’t come back yet
  • Fulfilled- promise was completed
  • Rejected- promise had an error
21
Q

How do you handle the fulfillment of a Promise?

A

Pass a function as the first argument to a .then method on the Promise

22
Q

How do you handle the rejection of a Promise?

A

Either pass a function as the second argument to a .then method, or a function as the only argument in a .catch method

23
Q

What is ‘array.prototype.filter’ useful for?

A

Helps with extracting certain values out of an array

24
Q

What is array.prototype.map useful for?

A

It is useful for manipulating/transforming elements inside an array (and getting a new array)

25
Q

What is Array.prototype.reduce useful for?

A

It is useful for “aggregating” elements in an array into a single entity, and the aggregation does not have to be simply mathematical operations on numbers. It can be used any time we have an array of things that we want to do stuff to, and we want the end result to be a single thing.

26
Q

What is “syntactic sugar”?

A

Syntax that makes code easier/”sweeter” to read for humans but can be removed without affecting the capabilities of the language

27
Q

What is the ‘typeof’ an ES6 class?

A

function

28
Q

Describe ES6 class syntax.

A
  • ## class keyword followed by the name of the class, then curly braces. Inside the braces, a function constructor which is called when a new object of that class is instantiated. The constructor function is followed by method definitions written like function definitions```javascript
    class Student {
    constructor(firstName, lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
    }
    getFullName() {
    return ${this.firstName} ${this.lastName};
    }
    }
    ~~~
29
Q

How are ES Modules different from CommonJS modules?

A

They have a different syntax (import and export instead of require() and module.exports)

30
Q

What kind of modules can Webpack support?

A
  • EcmaScript modules (ES)
  • CommonJS
  • AMD
31
Q

What does ‘fetch()’ mean?

A

A Promise that only resolves to reject if there is a network error that prevents the request from completing, otherwise a response object

32
Q

What is the default request method used by ‘fetch()’?

A

‘GET’

33
Q

How do you specify the request method (‘GET’, ‘POST’, etc.) when calling ‘fetch’?

A

After the URL, specify in the options object { method: 'GET' }