ES6 Flashcards
What is a code block?
What are some examples of a code block?
- Chunk of code within curly braces
- if statements, loops, functions
What does scope mean?
It’s not available outside of the code block that it’s currently inside of
What is the scope of a variable declared with const or let?
Block-scope
var is a function-scope
What is the difference between let and const?
- let can be updated but not re-declared
- const cannot be updated OR redeclared
Why is it possible to .push() a new value into a const variable that points to an Array?
Because it’s data in a reference – not the variable itself
How should you decide on which type of declaration to use?
If you know that your value will never change, use const – otherwise use let
What is the syntax for writing a template literal?
` ${ } `
What is “string interpolation”?
Embedding variables and expressions in a string
What is destructuring, conceptually?
o Extracting data from objects and arrays
o Taking objects and arrays and converting them into smaller objects, arrays, variables
What is the syntax for Object destructuring?
let { property1: variable1, propeprty2: variable2 } = objectName;
What is the syntax for Array destructuring?
let [x, y, z] = variableName
How can you tell the difference between destructuring and creating Object/Array literals?
var/let/const followed by {} or []
What is the syntax for defining an arrow function?
o Parameter => expression
o (parameter1, parameter) => expression
Note: Parentheses for parameters are needed only when there are >1 parameters
When an arrow function’s body is left without curly braces, what changes in its functionality?
Implicit return (It implies that you want to return)
Note: When you have curly braces, you have to explicitly write ‘return’
How is the value of this determined within an arrow function?
When the function is being defined (at definition time)