ES6 Flashcards

1
Q

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

A

where code is executed, usually inside curly brackets

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

What does block scope mean?

A

global or local, where a variable is accessible. if inside a code block and using let: the block scope is local. If outside of code block or var is used then block scope is global

let and const variables are only accessible inside the code 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, can only be accessed inside the code block if inside a code block

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–> can be changed and mutated within the scope
const: is immutable –> cannot be changed or reassigned, but can add inside

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

when pushing, you are not reassigning or redeclaring, you are adding to the object so techincally not really “changing” anything

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

when variable is not going to be reassigned use const, when it is, then use let

if read only use const

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

how can you change const variable

A

you can change const property values but not change the object literal

obj = {a: 2}
obj.a = 3  

not

obj = {a: 2}
obj = {a : 3}

you can also add (push) to const array

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

What is the syntax for writing a template literal?

A

back ticks –> some string
white spaces count
can do new line

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

What is “string interpolation”?

A

adding variable within template literal –>

const name = 'bob'
`my name is ${name}`
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is destructuring, conceptually?

A

assigning variables in regards to an object/ array structure
assigning it in a ‘backwards’ way

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

What is the syntax for Object destructuring?

A

{property1: var1, property2: var2} = object

if var is same name as property name –>
{var1, var2} = obj

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

What is the syntax for Array destructuring?

A

[var1, var2, var3] = array

to get leftovers –>
[var1, var2, …leftovers] = array

to skip through first values –>
[, , , var] = array

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

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

A

the variables are within an object bracket or array bracket and the assignment value is the object/array you are pulling value from

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

deconstructing objects with null returns from func

deconstructing array with null returns from fun

A

use OR operator and empty object as falback –>

let { firstName, lastName } = getPerson() || {};

let [a = 10, b = 20] = getItems() || [];

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

setting default values for array deconstruction

A

assign value within deconstructor

let [, , thirdItem = 0] = getItems();

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

What is the syntax for defining an arrow function?

A

const varName = (parameter) => { codeblock }

17
Q

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

A

right side must have return expression, if statement on right side, must put it inside curly braces

18
Q

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

A

value of [this] is determined when arrow function is defined

this becomes outside of scope but within function

since arrow function [this] is defined in definition time, when not inside a function, this in an arrow function becomes window

19
Q

What are the three states a Promise can be in?
How do you handle the fulfillment of a Promise?
How do you handle the rejection of a Promise?

A

pending, fulfilled, rejected

fulfillment of a promise is with .then( ) and whatever you want to happen

rejection of a promise is with .catch( ) or also.then( )

20
Q

What is Array.prototype.filter useful for?

A

to apply a call back function to each element of an array
returns a new array that applies to the condition of individal arrays

in the call back return has to be true or false to decide if it will be returned in the output array

21
Q

What is Array.prototype.map useful for?

A

to apply a callback function to each element of an array

22
Q

What is Array.prototype.reduce useful for?

A

to stack array values into one value

23
Q

What is “syntactic sugar”?

What is “refactoring”?

A

syntactic sugar is when you make a syntax “sweeter” to make things easier to read or express

refactoring is restructuring code without changing its functionality to make it easier to build onto or to read/understand

24
Q
What is the typeof an ES6 class?
Describe ES6 class syntax.
A

object,

class NameOfClass {

constructor(parameters) {

}

methods( ) {

} 

}