ES6 Flashcards
es6-const-let
What is a code block? What are some examples of a code block?
Where you write your code.
es6-const-let
What does block scope mean?
curly brances, if else, for, do while, while, try catch..
new variable in curly brace
not initialized to any value, not attached to the global object.
redeclaring a vasriable using the let keyword will cause an error.
A temporal dead zone of a variable declared using the let keyword starts from the block until the initialization is evaluated.
What is the scope of a variable declared with const or let?
const block scope, can’t be reassigned. immutable
let: block scope, can be reassigned whenever mutable
var only cares about function, var is function scoped.
What is the difference between let and const?
const block scope, can’t be reassigned. immutable
let: block scope, can be reassigned whenever mutable
Why is it possible to .push() a new value into a const variable that points to an Array?
Because it’s a read-only reference. Because you are not assigning. We are just changing the memory address.
How should you decide on which type of declaration to use?
If I want the variable to never be assigned, use const, in any case, if the variable needs to be reassigned, use let.
const is always better to use than let. Use const first.
What is the syntax for writing a template literal?
backtick(`) character
What is “string interpolation”?
String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.
What is destructuring, conceptually?
Getting data from arrays or objects
taking object properties and assigning them to separate variables.
a JavaScript expression that allows us to extract data from arrays, objects, and maps and set them into new, distinct variables
What is the syntax for Object destructuring?
let { property1: variable1, property2: variable2 } = object;
What is the syntax for Array destructuring?
const foo = [‘one’, ‘two’];
const [red, yellow, green, blue] = foo;
How can you tell the difference between destructuring and creating Object/Array literal?
destructuring assigns values to the properties
on the right side, we are creating, on the left side, we are destructuring.
What is the syntax for defining an arrow function?
(parameters) => {}
When an arrow function’s body is left without curly braces, what changes in its functionality?
if the curly brace is used return needs to be there.
if we want to put statements, they need to be in a curly brace.
How is the value of this determined within an arrow function?
Unlike regular functions, arrow functions do not have their own this. The value of this inside an arrow function remains the same throughout the lifecycle of the function and is always bound to the value of this in the closest non-arrow parent function.