es6 Flashcards
What is a code block? What are some examples of a code block?
code wrapped in curly braces ({}). if, if else, while, etc.
What does block scope mean?
Only accessible inside of the code block.
What is the scope of a variable declared with const or let?
block scope
What is the difference between let and const?
A constant variable cannot be reassigned. let variables can be reassigned
Why is it possible to .push() a new value into a const variable that points to an Array?
The value inside the array is not immuatable
How should you decide on which type of declaration to use?
Use let const unless you cant, then use let
What is destructuring, conceptually?
Assigning properties of an object or elements of an array to individual variables
What is the syntax for Object destructuring?
const/let {} = obj
What is the syntax for Array destructuring?
const let [] = obj
How can you tell the difference between destructuring and creating Object/Array literals?
an object literal / array literal is assigned to a variable in creation. In destructuring, the name of the created object/array is assigned to an object/array containing the variables.
What is the syntax for writing a template literal?
` ` and use ${} for string interpolation
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions
What is the syntax for defining an arrow function?
functionName = (parameters) => {expression}.
When an arrow function’s body is left without curly braces, what changes in its functionality?
Curly braces are not needed unless there is a statement being used
How is the value of this determined within an arrow function?
By where it is defined, not by who calls it