ES6 Flashcards
Variables defined with the var keyword are function scoped. const and let are _____ scoped.
block-scoped
Name some characteristics of a variable declared using const.
it is immutable, the value cannot be changed,
however properties can be assigned to it,
must initialize immediately
Name some characteristics of a variable declared using let.
mutable, value can be changed, and it does not have to be initialized
What does block scope mean?
its scope is defined by the curly braces it is contained in
In the file we can push a new value to an array defined using the const variable. How does that work?
it is a reference to the location in memory
Name some things that var can do that const and let can’t.
they are accessible outside of their blocks, can be hoisted, var can be redeclared, and redefined
If var can be used virtually anywhere, why would we switch?
minimize the errors that var can cause,
and to have absolute control over the variables being used , (ie no auto global variables)
What is the syntax in writing a template literal?
use the grave markers ` and then javascript expression ${}
${example}
What is string interpolation?
allows us to perform javascript expressions within strings
When was destructuring introduced?
2015 ES6
Why could the running commas technique of destructuring an array be a bad idea?
If an array is very large, you need a lot of commas; if so, just grab the value the normal way
How can you easily tell the difference between destructuring and creating array/object literals.
curly braces are on the left side of the equal sign
How does an ES6 arrow function differ from an ES5 function?
arrow functions dont need to be bound, and they are determined by lexical scope
When an arrow function’s code block is left without curly braces, what (if anything) changes in its functionality?
without curly braces, the code to the right of arrow will be implicitly returned
In what situations would you possibly use an arrow function?
callback functions where “this” will have a different value from its normal scope.