ES6 Flashcards
What is a code block? What are some examples of a code block?
Code blocks are denoted with curly brace brackets. Some examples include function code blocks, conditional statements, loop code blocks.
What does block scope mean?
The variable is only accessible within that code block.
Variables declared using var are accessible outside of a code block except for function code blocks
What is the scope of a variable declared with const or let?
Block-scoped
What is the difference between let and const?
‘let’ can be reassigned while ‘const’ cannot
Why is it possible to .push() a new value into a const variable that points to an Array?
The variable has the same memory address as its value, referring to a certain array. The array is mutable but the location in memory remains constant
The name binding cannot be changed
The array remains constant, not the elements within it
How should you decide on which type of declaration to use?
Rather than use ‘var’, use ‘const’ or ‘let’. If the variable is going to be changed from its initial value, use ‘let’
usually default to ‘const.’ If there is problems in the future, change to ‘let’
What is the syntax for writing a template literal?
backtick $ { } backtick
What is “string interpolation?”
Substituting parts of a string with the values of variables or expressions
What is destructuring, conceptually?
Taking the properties of an object and assigning them to multiple variables in one go
What is the syntax for Object destructuring?
const thing = {
this: 1,
that: 2,
};
const { this, that } = thing;
What is the syntax for Array destructuring?
const things = [
{this: 1, that 1},
{this: 2, that 2}
]
const [thing2, thing3] = things
How can you tell the difference between destructuring and creating Object/Array literals?
With destructuring, curly brackets on the left hand side of equal sign
With creating, curly brackets on the right hand side of equal sign
What is the syntax for defining an arrow function?
(parameter 1, parameter 2) => {code block}
When an arrow function’s body is left without curly braces, what changes in its functionality?
The arrow function returns value of the expression of the body without the curly brace (an implicit return)
How is the value of ‘this’ determined within an arrow function?
While regular function syntax will create a new function that creates its own this
, arrow functions do not create their own this
. Instead, it will be lexically scoped, so it will find the this
for the context that it is within
They don’t create their own this
binding
Value of this
is defined at definition time, not at call time (which is the case for traditional ES5 functions)
If you can’t see where it’s being called, this
might be referring to the global window
What is a CLI?
Command Line Interface
What is a GUI?
Graphical User Interface
Give at least one case for each of the commands used in this exercise.
- man: manual
- cat: concatenate files
- ls: list directory contents
- pwd: print working directory
- echo: display text
- touch: change file timestamps
- mkdir: make directories
- mv: move files
- rm: remove files
- cp: copy files
What are 3 virtues of a great programmer?
Laziness, impatience, hubris
What are the 3 states a Promise can be in?
- Pending- promise is created, promise hasn’t come back yet
- Fulfilled- promise was completed
- Rejected- promise had an error
How do you handle the fulfillment of a Promise?
Pass a function as the first argument to a .then
method on the Promise
How do you handle the rejection of a Promise?
Either pass a function as the second argument to a .then
method, or a function as the only argument in a .catch
method
What is ‘array.prototype.filter’ useful for?
Helps with extracting certain values out of an array
What is array.prototype.map useful for?
It is useful for manipulating/transforming elements inside an array (and getting a new array)
What is Array.prototype.reduce useful for?
It is useful for “aggregating” elements in an array into a single entity, and the aggregation does not have to be simply mathematical operations on numbers. It can be used any time we have an array of things that we want to do stuff to, and we want the end result to be a single thing.
What is “syntactic sugar”?
Syntax that makes code easier/”sweeter” to read for humans but can be removed without affecting the capabilities of the language
What is the ‘typeof’ an ES6 class?
function
Describe ES6 class syntax.
- ##
class
keyword followed by the name of the class, then curly braces. Inside the braces, a functionconstructor
which is called when a new object of that class is instantiated. The constructor function is followed by method definitions written like function definitions
```javascript
class Student {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
getFullName() {
return ${this.firstName} ${this.lastName}
;
}
}
~~~
How are ES Modules different from CommonJS modules?
They have a different syntax (import
and export
instead of require()
and module.exports
)
What kind of modules can Webpack support?
- EcmaScript modules (ES)
- CommonJS
- AMD
What does ‘fetch()’ mean?
A Promise that only resolves to reject if there is a network error that prevents the request from completing, otherwise a response object
What is the default request method used by ‘fetch()’?
‘GET’
How do you specify the request method (‘GET’, ‘POST’, etc.) when calling ‘fetch’?
After the URL, specify in the options object { method: 'GET' }