ES6 JavaScript Flashcards
What is a code block? What are some examples of a code block?
A block of code to be executed denoted by { curly braces }. Code blocks are found inside conditionals, loops, functions
What does block scope mean?
Any variables declared inside a code block only exist within that code block.
What is the scope of a variable declared with const or let?
both are block-scoped
What is the difference between let and const?
Const can’t be reassigned, where let can be reassigned.
Why is it possible to .push() a new value into a const variable that points to an Array?
Because we can mutate the elements of a mutable object like an array or plain object that is assigned to a const variable, and the array/object is not being reassigned.
How should you decide on which type of declaration to use?
Use the const keyword when defining a variable that should not be changed - use the let keyword where you intend on changing the value. Prefer const over let.
What is destructuring, conceptually?
Destructuring allows to unpack elements from an array and properties from objects and assign each to a variable.
What is the syntax for Object destructuring?
const { propertykeys: variableNames} = objectName
OR
const { propertyKeys, …} = objectName (if variable name = property name)
What is the syntax for Array destructuring?
const [ variableNames, … ] = arrayName
How can you tell the difference between destructuring and creating Object/Array literals?
object/array literal names are on the left when creating, on the right when destructuring
What is the syntax for writing a template literal?
A Template Literal uses backticks instead of single or double quotes. To insert a variable write a JavaScript Expression – ${variable}
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?
cont variable = (param1, param2…) = > { code block}
When an arrow function’s body is left without curly braces, what changes in its functionality?
If there are no curly braces there needs to be an expression following the arrow (rather than a statement) and the value of the expression is returned automatically (without return statement).
How is the value of this determined within an arrow function?
An arrow function captures the This value of the enclosing context instead of creating its own this context. the This is determined at definition time (rather than at call time like regular functions)