JavaScript ES6 Flashcards
What is a code block? What are some examples of a code block?
Code inside curly braces, like a function or if block
What does block scope mean?
Scoped inside of a code block. Not accessible outside the block.
What is the scope of a variable declared with const or let?
block scoped
What is the difference between let and const?
let is allows re-assignment. const does not allow re-assignment.
Why is it possible to .push() a new value into a const variable that points to an Array?
The address is immutable, but the object the address refers, too, is not. Therefore the object can be modified unless deep freezed.
How should you decide on which type of declaration to use?
If you intend to re-assign the value. Const protects the variable from being re-assigned.
What is the syntax for writing a template literal?
${variable_name inside back ticks
What is “string interpolation”?
The ability to substitute part of the string for the values of variables or expressions.
What is destructuring, conceptually?
Assigning properties of an object or elements of an array to individual variables.
What is the syntax for Object destructuring?
{ key1, key2, key3 } = obj
What is the syntax for Array destructuring?
[ var1, var2] = array
How can you tell the difference between destructuring and creating Object/Array literals?
destructoring is on the left side of the = sign, creating is on the right side
What are the three states a Promise can be in?
pending, fulfilled, rejected
How do you handle the fulfillment of a Promise?
then clause
How do you handle the rejection of a Promise?
catch clause
What is “syntactic sugar”?
Syntax designed to make code easier to read or express
What is the typeof an ES6 class?
function
Describe ES6 class syntax.
class keyword followed by name and braces. prototype methods in the class body.
What is “refactoring”?
process of restructuring code without changing its functionality to improve readability and maintainability
How are ES Modules different from CommonJS modules?
ES Modules can be statically analyzed (for static checking, optimization), better support for cyclic dependencies
What kind of modules can Webpack support?
ECMAScript modules, CommonJS modules, AMD modules, Assets, WebAssembly modules
What must the return value of myFunction be if the following expression is possible?
myFunction()();
return is a function
What does this code do? const wrap = value => () => value;
return value function
In JavaScript, when is a function’s scope determined; when it is called or when it is defined?
when it’s defined
What allows JavaScript functions to “remember” values from their surroundings?
closure