ES6 Flashcards
What is a code block? What are some examples of a code block?
In JavaScript, codeblocks are denoted by { } containing statements, ie(functions, conditionals, loops)
What does block scope mean?
the variable/declaration only exists within the block
What is the scope of a variable declared with const or let?
block-scoped
What is the difference between let and const?
let can be reassigned, const cannot
Why is it possible to .push() a new value into a const variable that points to an Array?
the const reference cannot be changed, but the value can
How should you decide on which type of declaration to use?
const should be used if possible, use let if variables have to be reassigned values
What is the syntax for writing a template literal?
same as regular strings except contained with backticks ( ` ), escape characters must be used if backticks are present in string ( /` ), no escape characters needed to go onto the next line either, just press enter
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions
What is destructuring, conceptually?
converting items in arrays/objects to single variables
What is the syntax for Object destructuring?
let { property1: variable1, property2: variable2 } = object;
What is the syntax for Array destructuring?
let [x,y,z] = [1,2,3]
How can you tell the difference between destructuring and creating Object/Array literals?
Objects include the property key and are in curly braces while arrays are in square braces
What is the syntax for defining an arrow function?
without block syntax, no return needs to be specified
(parameters) => returnvalue
with block syntax:
(parameters) => {return returnvalue}
When an arrow function’s body is left without curly braces, what changes in its functionality?
you can only have one statement and you don’t need a return statement (implicit return)
How is the value of this determined within an arrow function?
captures the this value of the enclosing context instead of creating its own this context