JS ES6 Flashcards

1
Q

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

A

{ }

code in curly brace

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

What does block scope mean?

A

scope of variables is only within curly braces

exist within the block and only affect code within the block; can see out but cannot see in

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: mutable variable
const: immutable variable, must be initialized with value, cannot use in imperative for loop (only for…of loop)

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

You can modify the values of properties, but not reassign a whole new array to a const variable (can’t change memory address 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 variable declaration to use?

A

Will the variable need to be changed within the code block?

Try to use const for everything. change to let if needed

use “const” if ARRAY, OBJECT
use “let” if LOOPS where variable is being modified

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

string ${variable}

backticks create template literals
${ } for substitutions

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

What is “string interpolation”?

A

Using backticks and can substitute part of a string with 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

destructure individual properties of an object or elements of an array into individual 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 } = object;

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 ,…args] = 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

the brackets are on the other side
creating = right side of equal sign
destructuring = left 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

const add() => { }

const add = (x, y) => x + y;

OR BLOCK SYNTAX
const add = (x, y) => { return x + y; };
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 = [implicit] return, no RETURN keyword needed (anything after arrow will be evaluated and auto returned)

with curly brace = [explicit return], works like regular function code block, need RETURN keyword

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

captures [this] value of enclosing context

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.

***promise always starts pending, either fulfilled/rejected (once fulfilled or rejected, cannot change)

17
Q

How do you handle the fulfillment of a Promise?

A

Promise.then(resolve (fulfillment), reject (rejection))

18
Q

How do you handle the rejection of a Promise?

A

Promise.catch

19
Q

Promise rejection - how to handle?

A

handle in .then 2nd arg

handle in .catch

20
Q

What is “syntactic sugar”?

A

syntax that is easier to read

21
Q

What is the typeof an ES6 class?

A

object

22
Q

Describe ES6 class syntax.

A
class ClassName {
   constructor(params) {
     this.params = params
    }

method( ) {
return something;
}

}

23
Q

What is refactoring?

A

Restructuring code without changing the behavior

24
Q

How are ES Modules different from CommonJS modules?

A

Common: require and module.exports

ES: import and export

25
Q

What kind of modules can Webpack support?

A

alot?

26
Q

CLOSURES

What must the return value of myFunction be if the following expression is possible?

myFunction()();

A

it needs to return a function

if you call this fxn, you are immediately calling another function and invoking the return fxn

27
Q

What does this code do?

const wrap = value => () => value;

A

wrap is a fxn that returns a fxn

wrap( ) returns the function [ ( ) => value ]

28
Q

In JavaScript, when is a function’s scope determined;

when it is called or when it is defined?

A

when it is called

29
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

closures due to the lexical scope (it pulls from the scope it was defined in)