ES6 Flashcards
What is a code block? What are some examples of a code block?
the code inside of curly braces {}
function code block, conditionals, etc
What does block scope mean?
The variables are only attached to what’s inside of the block, they do not attach to the global object (the window object)
What is the scope of a variable declared with const or let?
Const and Let are block-scoped - cannot be accessed outside particular block
What is the difference between let and const?
let can have its value reassigned, const cannot have its value reassigned.
Why is it possible to .push() a new value into a const variable that points to an Array?
.push is not reassigning or redeclaring the variable, it is simply adding to the array
How should have you decide on which type of declaration to use?
Use const by default unless the variable’s value will need to change
What is the syntax for writing a template literal?
use backticks `` and use ${variable}
What is “string interpolation”?
the ability to substitute part of a string for the values of variables or expression
What is destructuring, conceptually?
Taking data out of either an object or an array and assigning it to individual variables
What is the syntax for Object destructuring?
Const {propertyName: variable1, propertyName2: variable2; etc…} = objectName
What is the syntax for Array destructuring?
Const [variablename1, variablename2, variablename3, etc] = arrayName
How can you tell the difference between destructuring and creating Object/Array literals?
Curly Braces vs square brackets
What is the syntax for defining an arrow function?
Parameters => expression
Const fnName = (Parameters) => {codeblock with return}
When an arrow function’s body is left without curly braces, what changes in its functionality?
You can only put one expression to the right of the arrow, has an implicit return, result of that expression is returned
How is the value of this determined within an arrow function?
Has lexical scoping to this context
Value of this is defined at definition
What is a CLI?
Command Line Interface - connects user to a computer program or OS
Text based interface that runs programs, manage computer files and interacts with computer
What is a GUI?
Graphical User Interface - computer programs that provide a visual means for users to interact with an underlying application or system.
Give at least one use case for each of the commands listed in this exercise.
Man - manual, view the manual of the certain command
Cat - outputs content of the file or concat files together
Ls - lists directory contents
Pwd - display path of current working file(where am i?)
Echo -displays line of text within CLI(console.log for terminal)
Touch - update file access , modify time and create file if one does not exist
Mkdir - make a directory
Mv - move(rename) files (files name is its location)
Rm - remove(delete) directory -f is force delete
Cp - copy file or directory, can override an existing file
What are the three virtues of a great programmers?
Laziness, Impatience, Hubris
What is Node.JS?
Open source, cross platform runtime environment that allows developers to create all kinds of server-side tools and applications in javascript. Allow users to run javascript outside of the browser
What can Node.js be used for?
Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature. It’s used for traditional web sites and back-end API services, but was designed with real-time, push-based architectures in mind.
What is a REPL?
Read Eval Print Loop - takes user inputs, executes them and returns to user
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
python , node, php, javascript, ruby, java, GoLang, C#
What is the process object in a Node.js program?
It’s a global that provides information about, and control over, the current Node.js process.
How do you access the process object in a Node.js program?
As a global, it is always available to Node.js applications without using require(). It can also be explicitly accessed using require()
What is the data type of process.argv in Node.js?
Object
Array of strings
What is a JavaScript module?
Single .js file , each provide its own chunk of functionality
What values are passed into a Node.js module’s local scope?
exports, require, module, __filename, __dirname
Give two examples of truly global variables in a Node.js program.
Process and global
What is the purpose of module.exports in a Node.js module?
Be able to export code into another module
How do you import functionality into a Node.js module from another Node.js module?
require() and pass in the relative path of the file as a string argument
What is the JavaScript Event Loop?
responsible for executing the code, collecting and processing events, and executing queued sub-tasks
What is the difference between “blocking” and “non-blocking” with respect to how code is executed?
Fast vs slow code, prevents us from continuing the code and we can only proceed once the code block has been executed
What is a directory?
File system structure which contains references to other files and possibly other directories
What is a relative file path?
Location of file using current directory as a reference, uses current or parent directory as reference to specify path relative to it.
What is an absolute file path?
Specific location in a file system not related to current directory, specify location from root directory (/)
What module does Node.js include for manipulating the file system?
Fs module
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile()
Are file operations using the fs module synchronous or asynchronous?
yes
What is a client?
Someone who requests a service, browser and http pie
What is a server?
Program or device that receives requests from client and sends back data
Which HTTP method does a browser issue to a web server when you visit a URL?
`GET
What is on the first line of an HTTP request message?
HTTP method; a verb or noun that describes action being performed
The target request: either a URL or absolute path of the protocol, port, and domain are usually characterized by the request context.
HTTP version that is being used
What is on the first line of an HTTP response message?
Protocol version: http version
Status code: example 404
Status text: text description of the status code to help humans understand http message
What are HTTP headers?
Meta deta from the http request
Is a body required for a valid HTTP message?
No
What is NPM?
Node package manager, open source , world’s largest software registry, allows developers to share and borrow packages. Consists of three things: The website The CLI The registry
What is a package?
file or directory that is described by a package.json file. (must have this file).
all the files you need for a module
How can you create a package.json with npm?
npm init -yes
What is a dependency and how do you add one to a package?
packages required by your application
add by npm install (package name)
What happens when you add a dependency to a package with npm?
It adds library to json Object
How do you add express to your package dependencies?
create new project, npm init -yes
npm install express
verify it in the JSON object
What Express application method starts the server and binds it to a network port?
LISTEN
How do you mount a middleware with an express application?
USE
Which objects does an Express application pass to your middleware to manage?
req and res objects (Request and Response)
What is the appropriate CONTENT-TYPE header for HTTP messages to contain JSON in their bodies?
application/JSON
What does the express.json() middleware do and when would you need it?
parses incoming request with json payload and is based on body-parser. Where is the actual data? BODY!!!! (header/blank line/body) —> it looks for the json data in the body. Will send empty object if the JSON wasn’t sent correctly.
What is the significance of an HTTP request’s method?
HTTP defines a set of request methods to indicate the desired action to be performed for a given resource.
What are the three states a promise can be in ?
Pending: initial state
Fulfilled: meaning that the operation was successful
Rejected: operation failed
How do you handle the fulfillment of a Promise?
THEN method
How do you handle the rejection of a Promise?
CATCH method
What is Array.Prototype.Filter useful for?
Sort elements out of array with certain conditions
What is Array.Prototype.Map useful for?
Creates new array populated with the results of calling a provided function on every element in the calling array.
What is Array.prototype.Reduce useful for?
The reduce() method executes a user-supplied “reducer” callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
What is “syntactic sugar”?
Changing the syntax to make it easier to read or express
What is the typeOf an ES6 class?
FUNCTION
Describe the ES6 class syntax
class keyword nameOfClass{ constructor keyword(parameters){ } }
What is “refactoring”?
The process of restructuring existing computer code without changing or adding to its external behavior or functionality.
What is Webpack?
This is why webpack exists. It’s a tool that lets you bundle your JavaScript applications (supporting both ESM and CommonJS), and it can be extended to support many different assets such as images, fonts and stylesheets. Node js to bundle everything
How do you add a devDependency to a package?
–save-dev
What is an NPM Script?
Set of built-in and custom functions defined within the package.json file that all you to do certain things within your application
How do you execute webpack with npm run?
npm run
How are ES Modules different from CommonJS modules?
Their syntax is more compact
Their structure cam be statically analyzed
Their support for cyclic dependencies is better than CommonJSs
Specific keywords in ES , common JS calls functions
What kind of modules can Webpack support?
ECMAScript Modules, CommonJS, AMD Modules
What does fetch() return?
Returns a promise that resolves with a RESPONSE object
Doesnt contain actual JSON response body, but instead a representation of the entire http response.
Use the json() method which returns a second promise that resolves with the result of parsing the response body text as JSON
What is the default request method used by fetch()?
GET method
How do you specify the request method (GET, POST, etc.) when calling fetch?
Create a new request and in the second argument create an object literal with a method property with the value being whatever method you would like to use
What does express.static() return?
Returns ServeStatic function
Create a new middleware function to serve files from within a given root directory
What is the local __dirname variable in a Node.js module?
Absolute path of the directory name
What does the join() method of Node’s path module do?
Joins all the paths together into a single path string by puting slash between each
What must the return value of myFunction be if the following expression is possible?
myFunction()();
Must return another function
What does this code do? const wrap = value => () => value;
function that takes single param, and then there is a function that takes no params, and it returns the outter params.
In JavaScript, when is a function’s scope determined; when it is called or when it is defined?
At definition
What allows JavaScript functions to “remember” values from their surroundings?
closures
What does the acronym LIFO mean?
Last In First Out
What methods are available on a Stack data structure?
push(value), pop()
What must you do to access the value at an arbitrary point in a stack (not just the “top”)?
peek()
What does the acronym FIFO mean?
First In First Out
What methods are available on a Queue data structure?