ES6 Flashcards
What is a code block? What are some examples of a code block?
-Grouped zero or more statements within curly braces
What does block scope mean?
-A block scope is the area within if, switch conditions or for and while loops.
What is the scope of a variable declared with const or let?
-Those variables exist only within the corresponding block.
What is the difference between let and const?
-Variable declared by let are mutable but variables declared by const are immutable
Why is it possible to .push() a new value into a const variable that points to an Array?
- The const keyword ensures that the variable it creates is read-only
- However, it doesn’t mean that the actual value to which the const variable reference is immutable
How should you decide on which type of declaration to use?
-For read-only variables, use const
What is the syntax for writing a template literal?
- Use backticks instead of single or double quotes
- To substitute a variable and an expression, use this block: ${variable_name}
What is “string interpolation”?
-String interpolation allow you to embed variables and expressions in a string. The JavaScript engine will automatically replace these variables and expressions with their values.
What is destructuring, conceptually?
-Unpacking values from objects and arrays into variables
What is the syntax for Object destructuring?
- Variable declaration
- Curly braces
- The identifier before the colon (:) is the property of the object and the identifier after the colon is the variable
- Equal sign and object name
What is the syntax for Array destructuring?
- Variable declaration
- Square brackets with variable names separated by commas
- Equal sign and object name
How can you tell the difference between destructuring and creating Object/Array literals?
- When creating object/array literals, we assign the object to the variable
- When destructuring, we assign the object to the variable
What is the syntax for defining an arrow function?
- Use the (…args) => expression; to define an arrow function
- Use the (…args) => { statements } to define an arrow function that has multiple statements
When an arrow function’s body is left without curly braces, what changes in its functionality?
-If there are no curly braces, the expression is automatically returned from the arrow function
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
What are the three states a Promise can be in?
- pending
- fulfilled
- rejected
How do you handle the fulfillment of a Promise?
-.then()
How do you handle the rejection of a Promise?
- .then()
- .catch()
What is “syntactic sugar”?
-In computer science, syntactic sugar is syntax within a programming language that is designed to make things easier to read or to express.
What is the typeof an ES6 class?
-Function
Describe ES6 class syntax.
- class keyword, name of class
- Constructor keyword with argument followed by code block where properties of an instance are initialized
- function definition without the function keyword
What is “refactoring”?
-Process of restructuring existing code without changing its external behavior