JavaScript ES6 Flashcards
Variables defined with the var keyword are function scoped. const and let are _____ scoped.
block
Name some characteristics of a variable declared using const.
Preferred method,
Value of variable cannot be reassigned
Declares constants (immutable)
Not hoisted
Name some characteristics of a variable declared using let.
Value of variable can be changed (mutable)
Must use let in for loops
Not hoisted
What does block scope mean?
Only can be accessed inside the block of code declared/initialized and children scopes
In the file we can push a new value to an array defined using the const variable. How does that work?
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
Name some things that var can do that const and let can’t.
Cannot be access in the global Object (window)
Hoisted
can be redeclared, reassigned
If var can be used virtually anywhere, why would we switch?
Easy to make mistakes and reassign variables
What is the syntax in writing a template literal?
` text goes ${javascript } here`
What is string interpolation?
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
When was destructuring introduced?
ES6 (2015)
Why could the running commas technique of destructuring an array be a bad idea?
Might miscount the number of commas or miss some
Large arrays
How can you easily tell the difference between destructuring and creating array/object literals.
assignment and {} happens on the left side of the colon
How does an ES6 arrow function differ from an ES5 function?
ES6 - ‘this’, arguments, new.target, super have lexical scope and less wordy (don’t need function keyword)
binding won’t work
In what situations would you not want to use an arrow function?
In methods and constructors, not want to utilize lexical this
Lexical scope
Inherit’s parent’s this