JavaScript ES6 Flashcards

1
Q

Variables defined with the var keyword are function scoped. const and let are _____ scoped.

A

block

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

Name some characteristics of a variable declared using const.

A

Preferred method,
Value of variable cannot be reassigned
Declares constants (immutable)
Not hoisted

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

Name some characteristics of a variable declared using let.

A

Value of variable can be changed (mutable)
Must use let in for loops
Not hoisted

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

What does block scope mean?

A

Only can be accessed inside the block of code declared/initialized and children scopes

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

In the file we can push a new value to an array defined using the const variable. How does that work?

A
The binding or association between variable name and variable value (const x = []) is immutable, but the items at the indexes are mutable 
**Modifying the reference data type stored in memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Name some things that var can do that const and let can’t.

A

Cannot be access in the global Object (window)
Hoisted
can be redeclared, reassigned

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

If var can be used virtually anywhere, why would we switch?

A

Easy to make mistakes and reassign variables

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

What is the syntax in writing a template literal?

A

` text goes ${javascript } here`

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

What is string interpolation?

A

if you put a dynamically computed value inside a ${}, it is converted to a string and inserted into the string returned by the literal.
**Inject javascript into a string

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

When was destructuring introduced?

A

ES6 (2015)

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

Why could the running commas technique of destructuring an array be a bad idea?

A

Might miscount the number of commas or miss some

Large arrays

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

How can you easily tell the difference between destructuring and creating array/object literals.

A

assignment and {} happens on the left side of the colon

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

How does an ES6 arrow function differ from an ES5 function?

A

ES6 - ‘this’, arguments, new.target, super have lexical scope and less wordy (don’t need function keyword)
binding won’t work

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

In what situations would you not want to use an arrow function?

A

In methods and constructors, not want to utilize lexical this

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

Lexical scope

A

Inherit’s parent’s this

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

When an arrow function’s code block is left without curly braces, what (if anything) changes in its functionality?

A

one line statements will be implicitly returned

17
Q

In what situations would you possibly use an arrow function?

A

Callbacks, one line statements, lexical this