Backend Flashcards
Es-6-const-let
What is a code block? What are some examples of a code block?
Code blocks are denoted by curly braces. Examples are if else, for, do while, while, try catch and so on.
Es-6-const-let
What does block scope mean?
A block scoped variable means that the variable defined within a block will not be accessible from outside the block. A block can reside inside a function, and a block scoped variable will not be available outside the block even if the block is inside a function.
Es-6-const-let
What is the scope of a variable declared with const or let?
Block-scope
Es-6-const-let
What is the difference between let and const?
The const keyword cannot be reassigned, meaning it creates a read-only reference to a value. But the let keyword is mutable, meaning you can change its values anytime.
Es-6-const-let
Why is it possible to .push() a new value into a const variable that points to an Array?
We are not reassigning the value of a variable.
Es-6-const-let
How should you decide on which type of declaration to use?
If you don’t intend to modify the variable, then use the const keyword. Otherwise, use let keyword. Always default const if you are not sure.
Es-6-template-literals
What is the syntax for writing a template literal?
Keyword variable name equal sign backticks with text content.
Es-6-template-literals
What is “string interpolation”?
String interpolation is replacing placeholders with values in a string literal.
Es-6-destructuring
What is destructuring, conceptually?
Es-6-destructuring
What is the syntax for Object destructuring?
Es-6-destructuring
What is the syntax for Array destructuring?
Es-6-destructuring
How can you tell the difference between destructuring and creating Object/Array literals?
Es-6-arrow-functions
What is the syntax for defining an arrow function?
Variable keyword, function name, equal sign, parameters with parenthesis, arrow, function code block with curly braces if there is more than one line let add = (x, y) => x + y; let add = (x, y) => {return x + y};
Es-6-arrow-functions
When an arrow function’s body is left without curly braces, what changes in its functionality?
Implicitly return value
Es-6-arrow-functions
How is the value of this determined within an arrow function?
Refers to window object or global object
Arrow functions do not have their own this.
Whatever this is in the parent scope and it doesn’t create own lexical scope
Command-line-basics
What is a CLI?
Command-line interface
A command-line interpreter or command-line processor uses a CLI to receive commands from a user in the form of lines of text. This provides a means of setting parameters for the environment, invoking executables and providing information to them as to what actions they are to perform.
Command-line-basics
What is a GUI?
Graphical user Interface.
A GUI is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicators such as primary notation, instead of text-based UIs, typed command labels or text navigation.
Command-line-basics
Give at least one use case for each of the commands listed in this exercise.
- Man - Show manual page for a command. Look up what a command does
- Cat - concatenate files and print on the standard output
- Ls list directory content. - what directories we have
- Pwd to find out current directory you are in
- Echo - display line of text/string that passed as an argument
- Touch create a blank text file, Before creating a text file, it was used to change file access and modification time
- Mkdir create a new directory(folder)
- Mv - move a file or folder, but also rename the text
- Rm permanently remove a file or directory
- Cp - copy a file and can move to another directory
Command-line-basics
What are the three virtues of a great programmer?
- Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don’t have to answer so many questions about it.
- Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to.
- Hubris: The quality that makes you write (and maintain) programs that other people won’t want to say bad things about.
Node-Intro
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of a web browser.
Node-Intro
What can Node.js be used for?
Node.js can be used to build back ends for web applications, command-line programs or any kind of automation that developers wish to perform.
Node-Intro
What is a REPL?
Read-Evaluate-Print-Loop
Node-Intro
When was Node.js created?
May 27, 2009
Node-Intro
What back end languages have you heard of?
C++, C#, Ruby, PHP
Node-process-argv
What is the process object in a Node.js program?
The process object is a global that provides information about, and control over, the current Node.js process.
Node-process-argv
How do you access the process object in a Node.js program?
Type the process
Node-process-argv
What is the data type of process.argv in Node.js?
Array
Node-module-system
What is a JavaScript module?
It is a single .js file
Each file considers own module
Node-module-system
What values are passed into a Node.js module’s local scope?
Exports, require, module, __filename, __dirname
Node-module-system
Give two examples of truly global variables in a Node.js program.
process and console
Node-require
What is the purpose of module.exports in a Node.js module?
Assign a value and use it at some other file.
Node-require How do you import functionality into a Node.js module from another Node.js module?
Use require function and call the .js file
The-event-loop
What is the JavaScript Event Loop?
Look at the stack and task queue, if the stack is empty, it pushes callback to the stack
The-event-loop
What is different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking- slow, block the execution of JavaScript until a certain long task has finished
When blocking, prevent anything from happening. Nothing can happen.
Non-blocking is the asynchronous that it wouldn’t block and accept call back function
Push off to the side so that other codes can work.
node-fs-readfile
What is a directory?
Folder that contains multile files
node-fs-readfile
What is a relative file path?
file on the current working directory
node-fs-readfile
What is an absolute file path?
Root to all the way up to where the file is
node-fs-readfile What module does Node.js include for manipulating the file system?
fs module
node-fs-writefile What method is available in the Node.js fs module for writing data to a file?
fs.wrtieFile method
node-fs-writefile Are file operations using the fs module synchronous or asynchronous?
Asynchronous
http-message-recap
What is a client?
Service requester, requests content or service from a server
Program that requests to another program or computer
http-message-recap
What is a server?
The provider of a resource or service
The program listening to incoming response
http-message-recap
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
http-message-recap
What is on the first line of an HTTP request message?
HTTP method 2. The request target 3. The HTTP version
http-message-recap
What is on the first line of an HTTP response message?
The protocol version 2. Status code 3. Status text
A typical status line looks like: HTTP/1.1 404 Not Found.
http-message-recap
What are HTTP headers?
General headers, response headers, representation headers
HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value. Whitespace before the value is ignored.
http-message-recap
Is a body required for a valid HTTP message?
No, not all requests have one: requests fetching sources like GET, HEAD, DELETE or OPTIONS, usually don’t need one. BUT some requests send data to the server in order to update it: as often the case with POST requests (containing HTML form data).
npm-intro
What is NPM?
Package manager for JavaScript
Reeuse codes from other developers and share codes
npm is the world’s largest software registry
npm consists: the website, the command line interface(CLI) and the registry
npm-intro
What is a package?
Directory with one or more files in it.
Collection of files that are together to make up single program/library
npm-intro
How can you create a package.json with npm?
npm init —yes (default for setting)
npm-intro
What is a dependency and how to you add one to a package?
Dependencies are specified in a simple object that maps a package name to a version range.
You can add one to a package by npm i package name
npm-intro
What happens when you add a dependency to a package with npm?
You get node_modules with jquery
Express-intro
How do you add express to your package dependencies?
npm i express
Express-intro
What Express application method starts the server and binds it to a network PORT?
listen() method
express-hello-world
How do you mount a middleware with an Express application?
Use method
With optional mount path. ‘/user/:id’ The path for which the middleware function is invoked;
express-hello-world
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
Call back method Request object(req), response object(res) and the next middleware function(next)
express-get-json
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
express-delete
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. Although they can also be nouns, these request methods are sometimes referred to as HTTP verbs.
express-post-json
What does the express.json() middleware do and when would you need it?
express.json() returns a middleware that only parses JSON and only looks at request where the Content-Type header matches the type option. This parser accepts
Parse incoming base body, Needed when send data to the server
postgres-intro
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a powerful, open source object-relational database system
Other popular relational databases include MySQL, SQL Server by Microsoft, and Oracle by Oracle Corporation
postgres-intro
What are some advantages of learning a relational database?
If you are storing related data, then a relational database is probably a good first choice. A quality of many relational databases is that they support good guarantees about data integrity. They can store and modify data in a way that makes data corruption as unlikely as possible. This means that developers can set up their database to reject “bad” data and not worry about data being “half written”.
postgres-intro
What is one way to see if PostgreSQL is running?
Sudo service postgresql status
postgres-database
What is a database schema?
A collection of tables is called a schema. A schema defines how the data in a relational database should be organized.
postgres-database
What is a table?
A table is a list of rows like a spreadsheet where each row is a record in that spreadsheet. The Table is made of columns and rows and each row has the same set of attributes.
postgres-database
What is a row?
Row has the same set of attributes
Row is where the data is stored.
SQL-select
What is SQL and how is it different from languages like JavaScript?
SQL is Structured Query Language. SQL interact with database. SQL is a declarative programming language. In declarative languages, programmers describe the results they want and the programming environment comes up with its own plan for getting those results unlinke JavaScript which is imperative programming language that basically programers tell the JavaScript runtime what to do and how to do it .
SQL-select
How do you retrieve specific columns from a database table?
- The query starts with the select keyword
- The select keyword is followed by a comma-separated list of column names, each surrounded by “ double quotes.
- The column names are followed by a from clause specifying which table to retrieve the data from.
- The query must end in a ; semicolon
SQL-select
How do you filter rows based on some specific criteria?
where clause
- The where clause comes after the from clause
- The where clause is checking the “category” of each row in the table
- Text value, such as ‘cleaning’ are wrapped in a single quote. Not double quotes!
- The value of the text value column is being compared using a single = equal sign.
SQL-select
What are the benefits of formatting your SQL?
Makes it easier to read, maintain, and edit
SQL-select
What are four comparison operators that can be used in a where clause?
Equal sign(=), greater than(>), less than (>), and not equal to sign (!=)
SQL-select
How do you limit the number of rows returned in a result set?
- The limit clause comes last
- The limit clause includes a literal integer number with no quote to specify the maximum number of rows that should be returned
SQL-select
How do you retrieve all columns from a database table?
The * asterisk is followed by the select keyword
SQL-select
How do you control the sort order of a result set?
- The order by clause comes after the from clause.
- The order by clause is followed by a column name in “ double quotes.
- The default sort order of the results is ascending order.
SQL - Insert
How do you add a row to a SQL table?
Use insert statement to add rows to a table
SQL - Insert
What is a tuple?
A tuple is a list of values
SQL - Insert
How do you add multiple rows to a SQL table at once?
Separate more than one tuple of values separated by comma
SQL - Insert
How do you get back the row being inserted into a table without a separate select statement?
Returning clause with * asterisk
Returning only works with insert, update and delete
SQL-Update
How do you update rows in a database table?
Use update statment and set column to value and specify where(which one)
SQL-Update
Why is it important to include a where clause in your update statements?
Because if we don’t put the where clause to specify which one to update, every row will be updated with the same value.
SQL-Delete
How do you delete rows from a database table?
Delete statement where clause and returning clause
SQL-Delete
How do you accidentally delete all rows from a table?
Delete from table name and don’t specify which row you want to delete not indicating where clause
SQL-Join
What is a foreign key?
Instead of putting all information into one row, use one column that links two different SQL tables
Any columns that link tables together
SQL-Join
How do you join two SQL tables?
Join clause
SQL-Join
How do you temporarily rename columns or tables in a SQL statement?
Table name as keyword rename in the from and join clauses
SQL-Aggregates
What are some examples of aggregate functions?
max(), avg(), count(), min(), sum(), every()
SQL-Aggregates
What is the purpose of a group by clause?
The purpose is to separate rows into groups and perform aggregate function on those groups of rows.
es6-Promises
What are the three states a Promise can be in?
Pending: initial state, neither fulfilled nor rejected
Fulfilled: meaning that the operation was completed successfully
Rejected: meaning that the operation failed
es6-Promises
How do you handle the fulfillment of a Promise?
Then method passing resolve callback function with resolve value
es6-Promises
How do you handle the rejection of a Promise?
Catch method passing reject callback function with rejec value, error object
Array-filter
What is Array.prototype.filter useful for?
Filter in array and get a new array with filtered out result. Does not affect the original array
Array-map
What is Array.prototype.map useful for?
The map()method creates a new array populated with the results of calling a provided function on every element in the calling array.
Array-reduce
What is Array.prototype.reduce useful for?
The reduce() method is used to calculate a single value from an array. In other terms, the reduce() method reduces an array into a single value.