BackEnd Flashcards
What is a code block? What are some examples of a code block?
- lexical structure of source code that are grouped together. Code Blocks consist of one or more declarations and statements. (lexiscope refers to setting the scope, or range of functionality, of a variable so that it may be called (referenced) from within the block of code in which it is defined.)
- In JavaScript, code blocks are denoted by curly braces { }.
- For example, if else, for, do while, while and so on.
What does block scope mean?
Block scope means the variable definition is only valid within the block of code that it was declared in.
What is the scope of a variable declared with const or let?
const and let variables are Block-Scoped.
What is the difference between let and const?
Let can be reassigned and Const cannot.
Why is it possible to .push() a new value into a const variable that points to an Array?
It is possible to .push() to a new value into a const variable, because it is adding to the array instead of reassigning the variable.
The values in the array are mutable.
How should you decide on which type of declaration to use?
If the variable does not needed to be reassigned, then use const
What is the syntax for writing a template literal?
- put it inside backticks (``)
- ${ } holds the expressions and variables
example:
let name = ‘sharon’;
let age = 26;
phrase = hi my name is ${ name } and I am ${ age } years old
;
What is “string interpolation”?
String formatting: the ability to substitute part of the string for the values of variables or expressions.
What is restructuring conceptually?
Taking out part of an object and assigning it to new variables
What is the syntax for Object destructuring?
const { title, author, libraryID } = book1
What is the syntax for Array destructuring?
const [ book3, book4, book5 ] = getBooks()
How can you tell the difference between destructuring and creating Object/Array literals
the side of the assignment operator that the object or array is on.
creating object : def is right side of the equal sign
restructuring: { } and property name is on the left side of the =
What is the syntax for defining an arrow function?
functionName = parameter => {
code block
}
functionName = () => { }
() not needed with one parameter
() are needed with no parameter
{} needed for more than one line of code
When an arrow function’s body is left without curly braces, what changes in its functionality?
You don’t get a return statement.
How is the value of this determined within an arrow function?
this is defined at definition time for arrow functions. In other words, THIS is defined within the same lexiscope or parentscope.
For other functions, this is determined at call time
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of a web browser.
What can Node.js be used for?
Building back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.
What is a REPL?
A read–eval–print loop (REPL), also termed an interactive top-level or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user; a program written in a REPL environment is executed piecewise.
Chrome Dev Tools Console is one example.
This is more like a playground for testing things.
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
Node, Python, PHP, Ruby
What is the process object in a Node.js program?
• The process object is a global
• that global informs about and controls the current Node.js process.
• As a global, it is always available to Node.js applications without using require().
• It can also be explicitly accessed using require():
const process = require(‘process’);
How do you access the process object in a Node.js program?
Just type process, it is always available. Treat it like any other object.
It is a global so you can access it anywhere.
What is the data type of process.argv in Node.js?
Array
What is a JavaScript module?
Module in Node.js is a functionality organized in single or multiple JavaScript files that are reused.
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.
Console, process, global
What is the purpose of module.exports in a Node.js module?
It exports a module so other modules can use it
How do you import functionality into a Node.js module from another Node.js module?
Using the require function
What is the purpose of module.exports in a Node.js module?
Module exports are the instructions that tell Node. js which bits of code (functions, objects, strings, etc.) to export from a given file so that other files are allowed to access the exported code.
How do you import functionality into a Node.js module from another Node.js module?
Blocking assignment executes “in series” because a blocking assignment blocks execution of the next statement until it completes.
Non-blocking assignment executes in parallel because it describes assignments that all occur at the same time.
What is a directory?
An organizational structure and location for storing files.
What is a relative file path?
The location that is relative to where the file is.
./fileName
What is an absolute file path?
The path of the file from the root directory. (This is not a good idea to use because what is an absolute file path on my computer might not be the same for someone else’s computer).
What module does Node.js include for manipulating the file system?
the 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?
Both, since there are different sync versions, but fs.writeFile is asynchronous Asynchronous take callback arguments
What is npm?
npm is the world’s largest software registry. It can be used to share and borrow packages.
It has three components:
1. the website
2. the Command Line Interface (CLI)
3. the registry
What is a package?
a package is a package or module of code to reuse. It needs to be a directory with one or more files. It has a package.JSON file.
How can you create a package.json with npm?
Run the “npm init –yes” command on the command line
What is a dependency and how to you add one to a package?
dependencies are the modules that the project relies on to function properly.
npm install
What happens when you add a dependency to a package with npm?
The newly installed package(s) gets added to the list of dependencies in your package. json file
It downloads the packages that it depends on until it has everything.
How do you add express to your package dependencies?
run this command in the terminal while you are in the package directory:
npm install express
What Express application method starts the server and binds it to a network PORT?
listen( ) method.
app.listen([port [, host [, backlog] ] ][, callback])
What is a client?
a client is a piece of computer hardware or software that accesses a service made available by a server as part of the client–server model of computer networks.
What is a server?
a server is a piece of computer hardware or software (computer program) that provides functionality for other programs or devices, called “clients”.
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?
1.An HTTP method,
2. The request target,
3. The HTTP version
What is on the first line of an HTTP response message?
The protocol version, A status code, A status text.
What are HTTP headers?
It is meta-information about the request or describes the body included in the messages.
Is a body required for a valid HTTP message?
No. It is optional.
How do you mount a middleware with an Express application?
Middleware functions are functions that have access to the request object (req), the response object (res), They can be mounted with app.use
app.use((req, res) => { }
“the use method of the app object is being called with ONE argument with TWO PARAMETERS: req and use.”
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
the request and response objects
What is the appropriate Content-Type
application/JSON
What is the significance of an HTTP request’s method?
It tells what function your want to run in the code such as deleting and getting data in app.delete( ) and app.get( )
What does the express.json() middleware do and when would you need it?
parses incoming request bodies if payload is JSON. It is needed when content type header is application/json in the HTTP request.
In other words, it is a function or a program (or something) that is going to run between the time that the server gets the request and the time that the server sends the request out to the client. It is a function that happens between the beginning of the response and sending of the response.
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS). Other popular relational databases include MySQL (also free), SQL Server by Microsoft, and Oracle by Oracle Corporation.