ECMAScript 6 Flashcards
object = { ‘name’ : ‘Frank’, ‘age’ : 34 };
Show how to destructure the object into
var x, y;
( { name : x, age : y } = object );
What is the scoping of Var declared outside a function
Global
Object Destructuring
object = { ‘name’ : ‘Frank’, ‘age’ : 34 };
Show how to destructure the object into
var name, age;
[ name, age ] = object;
let b = 1; function () { let b = 2; }; What is b = ?
1
Show an example of a computed property name in an object.
object = {
[ “first” + “name”] : ‘Luther’
};
What does the ‘spread’ operator do?
It takes and array (list) and 'spreads' out the contents as if they were individual values applied separately. function threeParms(a, b, c) ... as in: var list = [ 10, 20, 26 ]; threeParam(...list);
Show the ES6 way to define a function within an object.
let object = { myFunction() { console.log('hello world'); } } object.myFunction();
What about const objects: const boss = { 'firstname': 'Chuck', 'lastname': 'Duncan' }; ... boss.firstname = 'Pat';
Is this valid?
Yes, because the constant has an object assigned to it and that hasn’t changed. What changed was the contents of the object. That is legal.
Can a LET variable be reassigned?
as in Let a = 5; Let a = 10;
No it will throw an exception.
What is the scope of a var inside a function
Just the function contents
What is the scoping of Let
Block scoping
What is the scoping rule for ‘const’?
Block scoped
function myFn( { ‘name’ = ‘Chuck’, ‘age’ = 69, ‘profession’ = ‘genius’ } = { } ) { … }
myFn( { ‘name’ : ‘Pat’, ‘profession’ = ‘retired’ } );
Explain…
The myFn arguments effectively replace the { } and the assignment continues. If NO parameter’s are given, the { } is applied, but the parameters each have default values, which are assigned.
What does the following produce:
var smallList = [ 'c', 'd', 'e' ]; var result = [ 'a', 'b', ...smallList, 'f', 'g' ]
result = [ ‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’ ]
Where is the ‘rest’ operator used?
In declaring a function; it embodies the ‘rest’ of the parameters that may have optionally been supplied:
function trafficTypes( lane, speed, …other );