es6 Flashcards
What is a code block? What are some examples of a code block?
if else, for, do while, while, try catch
What does block scope mean?
the variable defined within the code block (i.e., within the brackets of an if condition, for loop, etc) is only “accessible” within that code block itself - meaning, the variable and it’s respective value are only within that code block, i.e., whatever is defined/assigned in the block scope are rendered as “new” definitions/assignments
What is the difference between let and const?
the const blocked-scoped variables cannot be reassigned/redeclared (immutable) as opposed to the let blocked-scoped variables can be reassigned (mutable)
if you try to reassign const, you receive a type error (TypeError)
const variables must have an initialized value otherwise you get a syntax error (SyntaxError)
use let if we intend on modifying the variable
using const in a for loop will only evaluate the declaration once before the loop body starts
What is the difference between let and const?
the const blocked-scoped variables cannot be reassigned/redeclared (immutable?) as opposed to the let blocked-scoped variables can be reassigned (mutable?)
if you try to reassign const, you receive a type error (TypeError)
const variables must have an initialized value otherwise you get a syntax error (SyntaxError)
use let if we intend on modifying the value of the variable; we can’t modify the variable itself
using const in a for loop will only evaluate the declaration once before the loop body starts
using let does not attach the variable to the global object as property (like the var keyword does)
let creates a new variable in each iteration in a for loop (like var)
Why is it possible to .push() a new value into a const variable that points to an Array?
the const variable, in this case, an array, itself is immutable; on the other hand, the array itself is mutable - meaning, you can add new things to the array
think reassignment
What is the syntax for writing a template literal?
wrapping your text/string in backticks as opposed to double/single quotes
const name = jane doe
What is the syntax for writing a template literal?
wrapping your text/string in backticks as opposed to double/single quotes
dollar sign curly and expression within
features of template literals
- A multiline string: a string that can span multiple lines.
- String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.
- HTML escaping: the ability to transform a string so that it is safe to include in HTML.
What is destructuring, conceptually?
damn
What is destructuring, conceptually?
extracting; taking values out of the structure
What is the syntax for Array destructuring?
i.e., const array = [1, 2, 3, 4];
const [first, ,third] = array;
console.log(first, third); // 1 3
How can you tell the difference between destructuring and creating Object/Array literals?
deconstructing statement, i.e., the object/array is “rewritten” per se
How can you tell the difference between destructuring and creating Object/Array literals?
{} [] is the left of the assignment operator means creating
while on the right of the assignment operator means destructuring
What is the syntax for defining an arrow function?
() => parameters are optional;
if one parameter, optional parantheses
if more than one parameters, mandatory paranthesis
When an arrow function’s body is left without curly braces, what changes in its functionality?
no return keyword;
and thus has to be an expression