ES6 JS Flashcards
What is a code block? What are some examples of a code block?
The code block is a location where we write codes between the curly braces.
{}
What does block scope mean?
It restricts the variable that is declared inside the specific block from being accessed from outside of the block
What is the scope of a variable declared with const or let?
blocked-scope
What is the difference between let and const?
You can change the value assigned to the let
keyword while const you cannot.
Why is it possible to .push() a new value into a const variable that points to an Array?
Because you are not reassigning a different array to the const variable, you are simply adding a value to the same array
The object is still mutable when it’s assigned to a variable so you can add data to it
How should you decide on which type of declaration to use?
If you need to reassign values to the variable, then you should use let
What is the syntax for writing a template literal?
${variable}
What is “string interpolation”?
ability to substitute part of the string for the values of variables or expressions
substitute a variable with a string
What is destructuring, conceptually?
JS expression that makes it possible to unpack elements from arrays or properties from objects, into distinct variables
It’s how you get object properties or array elements into one line
What is the syntax for Object destructuring?
let { property1: variable1, property2: variable2 } = object;
What is the syntax for Array destructuring?
let [x, y, z] = variableName
How can you tell the difference between destructuring and creating Object/Array literals?
you have the variable name to the left of the ‘=’ operator when creating object/array literals. Whereas, the variable name is on the right when destructuring.
What is the syntax for defining an arrow function?
parameter => expression
param => { statement }
When an arrow function’s body is left without curly braces, what changes in its functionality?
It has an implicit return
You will need a curly braces when you have multiple lines of statement with a return statement
How is the value of this determined within an arrow function?
parent’s code block and is being determined at definition time
What is a CLI?
Command-line interface
to receive commands from a user in the form of lines of text
What is a GUI?
Graphical user interface
For users to interact with graphical icons
Give at least one use case for each of the commands listed in this exercise.
man, cat, ls, pwd, echo, touch, mkdir , mv, rm, cp
man - interface to the system reference manuals
cat - concatenate files and print on the standard output
ls - list directory contents
pwd - print name of current/working directory
echo - display a line of text
touch - change file timestamps
mkdir - make directories
mv – move (rename) files
rm - remove files or directories
cp - copy files and directories
What are the three states a Promise can be in?
pending, fulfilled, or rejected
How do you handle the fulfillment of a Promise?
.then() - pass in callback function
When the promise is fulfilled, this code is used to execute the function
How do you handle the rejection of a Promise?
.catch() - pass in a callback function, if the promise is rejected, this code will be executed
What is Array.prototype.filter useful for?
It creates a new array filled with elements that pass a test provided by a function
What is Array.prototype.map useful for?
you can format it into a string
What is Array.prototype.reduce useful for?
we can use it to turn the array into an object
return a single value from an array
What is “syntactic sugar”?
That allows code to become easier to read or friendly but at the cost of flexibility
What is the typeof an ES6 class?
object
Describe ES6 class syntax.
class ClassName {
constructor(param) {
// stuff
}
methodName(param) {
// more stuff
}
}
What is “refactoring”?
Process of restructuring existing computer code without changing its functionality
How are ES Modules different from CommonJS modules?
each dependency is stored in its file for ES Modules. This allows developers to better control how their dependencies are used. Whereas, CommonJS keeps all the files in one file named node_modules
ES6 has a greater functionality attached to it
What kind of modules can Webpack support?
ESMAScript modules
CommonJS modules
amd MODULES