ES-6 Flashcards
what is a code block? what are examples of a code block?
chunk of code to define statements to be executed together indicated by curly braces
ex. functions, for loops, conditionals (if statements)
what does block scope mean?
block scope refers to the area within code block
variables exist only 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?
const keyword creates block-scoped variables whose values can’t be reassigned
let - mutable, const- immutable
why is it possible to .push( ) a new value into a const variable that points to an Array?
value of the const variable is mutable
how should you decide on which type of declaration to use?
consider if the variable needs to be reassigned later on within the block scope - if so, let
const - no reassignment
let - reassignment
favor const over let - when you are stuck in a situation where const won’t work, use let
what is destructuring, conceptually?
allows you to unpack values from arrays, or properties from objects, into distinct variables
what is the syntax for Object destructuring? ** { } curly braces for destructuring isn’t considered a code block
const/let keyword, curly braces, variable names within curly brace, assignment operator, variable
what is the syntax for Array destructuring? ** { } curly braces for destructuring isn’t considered a code block
const/let keyword, brackets, variable names, assignment operator, variable
how can you tell the difference between destructuring and creating Object / Array literals?
destructuring, check for variable name at the end
or if there is no variable name following const/let
what is the syntax for writing a template literal?
using back ticks ` `, ${ } for variables
what is “string interpolation?”
ability to substitute part of the string for the values of variables or expressions
what is the syntax for defining an arrow function?
one param - param => expression (for anonymous)
multiple params - (param1, param2) => expression, requires parantheses
multiple statements - require body brackets and return
when an arrow function’s body is left without curly braces, what changes in its functionality?
it will return a value without the return keyword (implicit return)
how is the value of this determined within an arrow function?
the this value is determined by 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?
promise.then(onFulfilled[,onRejected])
or
promise.then(value => {//code for fulfillment}
how do you handle the rejection of a promise?
promise.then
or promise.catch
what is syntactic sugar?
syntax that is designed to make things easier to read or to express
what is the type of an ES6 class?
function
describe ES6 class syntax
class declaration, class name
constructor with parameter(s), followed by code block
followed by any functions you want to implement
what is refactoring?
process of restructuring existing computer code without changing its external behavior/output
how are ES modules different from CommonJS modules?
ES modules syntax are even more compact than CommonJS
structure can be statically analyzed
their support for cyclic dependencies are better than CommonJS
what kind of modules can Webpack support?
EMCAScript, CommonJS, AMD (asynchronous module definition)
what is Webpack?
a tool that lets you bundle your JS applications
how do you add a DevDependency to a package?
npm install –save-dev
what is an NPM script?
supports number of built-in scripts and their preset lifecycle events
how do you execute Webpack with npm run?
add an npm script
npm run build