ES6 Flashcards
What is a code block? What are some examples of a code block?
Piece of code that is to be ran.
Function code block
Conditional code block
Loop code block
What does block scope mean?
The area inside a code block.
What is a block scoped variable?
Exists inside code block only
What is the difference between let and const?
let is:
mutable, not attached to the global object
Can be reassigned
const is:
immutable, read-only (cannot be changed but properties can be altered).
Cannot be reassigned
Why is it possible to .push( ) a new value into a const variable that points to an Array?
Push works because you’re not reassigning the data type of the array is but changing contents of the array.
How should you decide on which type of declaration to use?
Use const unless you cant.
If variable will get reassigned use let.
What is the syntax for writing a template literal?
Backticks ``
Strings
Expressions (using ${JavaScript expression}
- Any expression that has a value could be used
What is ‘string interpolation’?
The substitution of a string using the values of expressions and variables
${expressionName}
What is destructuring, conceptually?
A way to extract values from declared arrays and objects
What is the syntax for Object destructuring?
variable keyword curly braces property names variable names (if not using property names) equal sign object name
What is the syntax for Array destructuring?
const [x, y, z] = arrayName
variable keyword brackets element names in array variable name (if not using element name) equal sign array name
How can you tell the difference between destructuring and creating Object/Array literals?
Destructuring curly braces/brackets on the left side and object/array name on right side
Creating curly braces/brackets on the right side and object/array name on left side
What is the syntax for defining an arrow function?
(p1, p2, …, pn) => expression;
Variable (optional dependent on use case)
Parameters in parentheses (optional)
Arrow function
Code block or expression
When an arrow function’s body is left without curly braces, what changes in its functionality?
Without curly brace return is implied
With curly brace return statement is needed
How is the value of this determined with an arrow function?
With whatever this was assigned to