es6 Flashcards
What is a code block? What are some examples of a code block?
code block is a group of code put together to be executed. There are function code blocks, css ruleset code blocks, conditional code blocks… etc
What does block scope mean?
value of the variable is particular to that specific block. the value of the variable only changes in that block, but the original value does not change. Because the let keyword declares a block-scoped variable, the x variable inside the if block is a new variable and it shadows the x variable declared at the top of the script.
What is the scope of a variable declared with const or let?
They are both blocked-scope variables. They are neither global or local.
What is the difference between let and const?
block-scoped variables declared by the const keyword can’t be reassigned. the variables declared by the let keyword are mutable.
Why is it possible to .push() a new value into a const variable that points to an Array?
you can change the value of its property, but you cannot reassign a different value to the const variable.
How should you decide on which type of declaration to use?
If you intend to not change the value of the variable, use const. However, if you need to reassign a variable, use let.
What is the syntax for writing a template literal?
use backticks instead of single or double quotes. you can use $ and curly braces for JavaScript expressions
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions.
What is destructuring, conceptually?
assigns properties of an object to individual variables.
What is the syntax for Object destructuring?
const keyword, opening curly braces,comma to separate property value pairs. assignment operator and object name. If the variables have the same names as the properties of the object, you can make the code more concise by just having the property names and separate them with comma.
What is the syntax for Array destructuring?
const keyword, opening square brackets, variable names assignment operator and object name..
How can you tell the difference between destructuring and creating Object/Array literals?
desturcturing the curly braces are on the left and object name is on the right side of assignment operator. creating the curly braces are on the right and object name is on the left side of assignment operator.
What is the syntax for defining an arrow function?
const keyword, name of function, assignment operator, optional parenthesis for 2 or more parameters, arrow, and optional curly braces if return statement is present for code block. If no parameter, need to have empty parenthesis.
When an arrow function’s body is left without curly braces, what changes in its functionality?
for javascript expressions, you dont need curly braces. For mutiple-lined statements you need curly braces. you dont need a return statement for non-curly braces
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. Based on surrounding scope, this was defined in.