ES6 Flashcards
What is a code block? What are some examples of a code block?
statements inside curly brackets
statements inside of functions, conditionals or loops
What does the block scope mean?
area within conditionals or loops
something that only exists within the corresponding block
What is the scope of a variable declared with const or let?
block-scope
What is the difference between let and const?
et can be reassigned, const cannot
Why is it possible to .push() a new value into a const variable that points to an Array?
you can change the elements inside of the array, but cannot reassign that array to another array
How should you decide which type of declaration to use?
should use const for anything that will be a constant variable. anything that will need to be reassigned should be let
What is the syntax for writing a template literal?
wrapping your text in backticks accounting for whitespace
What is string interpolation?
the ability to substitute part of the string for the values of variables or expressions
the javascript engine will automatically replace these variables and expressions by their values
What is destructuring conceptually?
an expression that makes it possible to unpack values from arrays or properties from objects, into distinct variables
What is the syntax for Object destructuring?
var, const or let keyword followed by curly braces and the properties you want assigned separated by a colon from the names of the variables you want them assigned to and the object name at the end following the closing curly brace and assignment operator
What is the syntax for Array destructuring?
var, const or let keyword followed by brackets and the variable names you want assigned in the order of the indexes you want assigned to them and the array literal name at the end following the closing bracket and assignment operator
How can you tell the difference between destructuring and creating object/array literals?
object/array name is always at the end when destructuring following the closing curly brace/bracket and the assignment operator
What is the syntax for defining an arrow function?
remove the function keyword.
parameters are listed (if more than one, listen within parentheses) followed by function arrow
multiline statements require body brackets and return
When an arrow function’s body is left without curly braces, what changes in its functionality?
you can use an expression without curly braces but not a statement
How is the value of this determined within an arrow function?
arrow functions establish this based on the scope the arrow function is defined within
in regular functions the this keyword represented the object that called the function, which could be the window, the document, a button, etc
with arrow functions, this always represents the object that defined the arrow function