m-2-0522 Flashcards
What is a method?
A method is a function which is a property of an object.
How can you tell the difference between a method definition and a method call?
method definition is found inside the declaration of an object
method call is done by using name of the object followed by a period and the name of the method
Describe method definition syntax (structure).
var object = { method: function () { } };
Describe method call syntax (structure).
object.method();
How is a method different from any other function?
A method is a property of an object.
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods)
What are the four “principles” of Object-Oriented Programming?
Abstraction
Encapsulation
Inheritance
Polymorphism
What is “abstraction”?
being able to work with (possibly) complex things in simple ways
What does API stand for?
application programming interface
What is the purpose of an API?
to give programmers a way to interact with a system in a simplified, consistent fashion
What is this in JavaScript?
the value of this is determined by how a function is called
this describes the current context you’re in
What does it mean to say that this is an “implicit parameter”?
meaning that it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var
When is the value of this determined in a function; call time or definition time?
the value of this is determined when the function is called
What does this refer to in the following code snippet? var character = { firstName: 'Mario', greet: function () { var message = 'It\'s-a-me, ' + this.firstName + '!'; console.log(message); } };
window object
Given the above character object, what is the result of the following code snippet? Why?
character.greet();
It’s-a-me, Mario!
Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello();
It’s-a-me, undefined!
How can you tell what the value of this will be for a particular function or method definition?
we can’t
How can you tell what the value of this is for a particular function or method call?
Find where the function is called and look for an object to the left of the dot
What kind of inheritance does the JavaScript programming language use?
prototype-based (or prototypal) inheritance
What is a prototype in JavaScript?
a JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects
How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?
prototype-based inheritance
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
prototype object
What does the new operator do?
The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.
What property of JavaScript functions can store shared behavior for instances created with new?
prototype property
What does the instanceof operator do?
The instanceof operator tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object. The return value is a boolean value.
What is a “callback” function?
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
Besides adding an event listener callback function to an element or the document, what is one way to delay the execution of a JavaScript function until some point in the future?
setTimeout()
How can you set up a function to be called repeatedly without using a loop?
setInterval()
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
What do setTimeout() and setInterval() return?
The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout(). This value can be passed to clearTimeout() to cancel the timeout.
The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.
What is a client?
a service requestor
What is a server?
provider of a resource or service
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What three things are on the start-line of an HTTP request message?
HTTP method, request target, and HTTP version
What three things are on the start-line of an HTTP response message?
The protocol version, a status code, a status text
What are HTTP 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.
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN
Is a body required for a valid HTTP request or response message?
no
What is AJAX?
AJAX is a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest. Ajax allows you to update parts of the DOM of an HTML page without the need for a full page refresh. Ajax also lets you work asynchronously, meaning your code continues to run while the targeted part of your web page is trying to reload (compared to synchronously, which blocks your code from running until that part of your page is done reloading). With interactive websites and modern web standards, Ajax is gradually being replaced by functions within JavaScript frameworks and the official Fetch API Standard.
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
Which object is built into the browser for making HTTP requests in JavaScript?
To perform Ajax communication JavaScript uses a special object built into the browser—an XMLHttpRequest (XHR) object—to make HTTP requests to the server and receive data in response.
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
they have a shared prototype object
What is a code block? What are some examples of a code block?
a group of zero or more statements
What does block scope mean?
The current context of execution. The context in which values and expressions are “visible” or can be referenced.
What is the scope of a variable declared with const or let?
block scope
What is the difference between let and const?
let can be updated but not re-declared.
const cannot be updated or re-declared.
Why is it possible to .push() a new value into a const variable that points to an Array?
in this situation, the const variable is a reference to the array. the reference cannot be changed, but the values in the array can be.
How should you decide on which type of declaration to use?
scope
reassignment
redeclaration
What is the syntax for writing a template literal?
To create a template literal, instead of single quotes ( ‘ ) or double quotes ( “ ) quotes we use the backtick ( ` ) character.
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions
What is destructuring, conceptually?
unpack values from arrays, or properties from objects, into distinct variables
What is the syntax for Object destructuring?
const user = { id: 42, isVerified: true };
const {id, isVerified} = user;
console. log(id); // 42
console. log(isVerified); // true
What is the syntax for Array destructuring?
const foo = [‘one’, ‘two’, ‘three’];
const [red, yellow, green] = foo;
console. log(red); // “one”
console. log(yellow); // “two”
console. log(green); // “three”
How can you tell the difference between destructuring and creating Object/Array literals?
the object/array are on the left side or no side when creating
the object/array are on the right side when destructuring
What is the syntax for defining an arrow function?
One param. With simple expression return is not needed:
param => expression
Multiple params require parentheses. With simple expression return is not needed:
(param1, paramN) => expression
Multiline statements require body braces and return: param => { let a = 1; return a + param; }
Multiple params require parentheses. Multiline statements require body braces and return: (param1, paramN) => { let a = 1; return a + param1 + paramN; }
When an arrow function’s body is left without curly braces, what changes in its functionality?
expression vs statement
How is the value of this determined within an arrow function?
an arrow function captures the this value of the enclosing context instead of creating its own this context
What is a CLI?
command line interface
What is a GUI?
graphical user interface
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 - manual
cat - cat command allows us to create single or multiple files, view content of a file, concatenate files and redirect output in terminal or files
ls - It allows users to list files and directories from the Command Line Interface
pwd - printing current working directory
echo - echo is a command that outputs the strings that are passed to it as arguments
touch - The touch command’s primary function is to modify a timestamp. Commonly, the utility is used for file creation, although this is not its primary function.
mkdir - allows users to create or make new directories
mv - moves files or directories from one place to another
rm - The rm command is used to delete files.
cp - The cp command is a command-line utility for copying files and directories.
What are the three virtues of a great programmer?
laziness, impatience, hubris
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?
It is commonly used to build 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 toplevel 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.
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
Python, Java
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.
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():
const process = require(‘process’);
What is the data type of process.argv in Node.js?
string type
What is a computer process?
In computing, a process is the instance of a computer program that is being executed by one or many threads. It contains the program code and its activity. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently.
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
134 processes
Why should a full stack Web developer know that computer processes exist?
Full stack Web development is based on making multiple processes work together to form one application, so having at least a cursory awareness of computer processes is necessary. This will be extremely important when learning about applications made of multiple components, such as clients, servers, and databases.
What is a JavaScript module?
In JavaScript, a “module” is a single .js file.
What values are passed into a Node.js module’s local scope?
The five parameters — exports, require, module, __filename, __dirname are available inside each module in Node. Though these parameters are global to the code within a module yet they are local to the module (because of the function wrapper as explained above). These parameters provide valuable information related to a module.
Give two examples of truly global variables in a Node.js program.
console and process
What is the purpose of module.exports in a Node.js module?
The main purpose of module. exports is to achieve modular programming. Modular programming refers to separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality.
How do you import functionality into a Node.js module from another Node.js module?
To include functions defined in another file in Node.js, we need to import the module. we will use the require keyword at the top of the file.
What is the JavaScript Event Loop?
The event loop is a constantly running process that monitors both the callback queue and the call stack.
What is different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking methods execute synchronously and non-blocking methods execute asynchronously.
What is a directory?
In computing, a directory is a file system cataloging structure which contains references to other computer files, and possibly other directories.
What is a relative file path?
Relative Path is the hierarchical path that locates a file or folder on a file system starting from the current directory.
What is an absolute file path?
An absolute path always contains the root element and the complete directory list required to locate the file.
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?
writeFile method
Are file operations using the fs module synchronous or asynchronous?
asynchronous
What is a client?
service requestor
What is a server?
provider of a resource or service
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, request target, http version
What is on the first line of an HTTP response message?
protocol version, status code, status text
What are HTTP headers?
additional information passed by the client and/or server with an HTTP request or HTTP response
Is a body required for a valid HTTP message?
no
What is NPM?
node package manager
npm is the world’s largest software registry
What is a package?
a directory with one or more files in it that also has a file called package.json with some metadata about the package
How can you create a package.json with npm?
npm init
What is a dependency and how to you add one to a package?
A dependency is a library that a project needs to function effectively
npm install [ …]
What happens when you add a dependency to a package with npm?
you can use that code with your code
How do you add express to your package dependencies?
$ npm install express
What Express application method starts the server and binds it to a network PORT?
the listen() method
How do you mount a middleware with an Express application?
calling the use method of the Express application object
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
the req object and the res object
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json; charset=utf-8
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.
Specificity; (url is the resource) request method is what you’re doing with that resource
What does the express.json() middleware do and when would you need it?
This is a built-in middleware function in Express. It parses incoming requests with JSON payloads and is based on body-parser.
Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option. This parser accepts any Unicode encoding of the body and supports automatic inflation of gzip and deflate encodings.
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body), or an empty object ({}) if there was no body to parse, the Content-Type was not matched, or an error occurred.
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.
What are some advantages of learning a relational database?
relational databases are good at storing related data and support good guarantees about data integrity
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
A collection of tables
What is a table?
A table is a list of rows each having the same set of attributes.
What is a row?
a record of data
What is SQL and how is it different from languages like JavaScript?
Structured Query Language is a programming language designed for managing (retrieving, creating, and manipulating) data held in a relational database management system. SQL is declarative. JavaScript is imperative.
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 keywords such as select and from are not case-sensitive.
SQL does not have to be indented, but you should do it anyway for consistent style and therefore readability.
How do you filter rows based on some specific criteria?
select "productId", "name", "price" from "products" where "category" = 'cleaning';
What are the benefits of formatting your SQL?
SQL does not have to be indented, but you should do it anyway for consistent style and therefore readability.
What are four comparison operators that can be used in a where clause?
Other comparisons like <, >, and != are available too
How do you limit the number of rows returned in a result set?
select "name", "description" from "products" order by "price" desc limit 1;
How do you retrieve all columns from a database table?
select *
from “products”;
How do you control the sort order of a result set?
select *
from “products”
order by “price”;
How do you add a row to a SQL table?
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);
What is a tuple?
a list of values
How do you add multiple rows to a SQL table at once?
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’),
(‘Tater Mitts’, ‘Scrub some taters!’, 6, ‘cooking’)
returning *;
How do you get back the row being inserted into a table without a separate select statement?
returning clause
How do you update rows in a database table?
update “products”
set “price” = 100;
Why is it important to include a where clause in your update statements?
to only target specific rows
How do you delete rows from a database table?
delete from “products”
where “productId” = 24
returning *;
How do you accidentally delete all rows from a table?
delete from “products”;
What is a foreign key?
an attribute that links to another table
How do you join two SQL tables?
select *
from “products”
join “suppliers” using (“supplierId”);
How do you temporarily rename columns or tables in a SQL statement?
select “products”.”name” as “product”,
“suppliers”.”name” as “supplier”
from “products”
join “suppliers” using (“supplierId”);
What are some examples of aggregate functions?
max(), avg(), count(), min(), sum(), every()
takes a list of values and creates a single value
What is the purpose of a group by clause?
to separate rows into groups and perform aggregate functions on those groups of rows
What are the three states a Promise can be in?
pending
fulfilled
rejected
How do you handle the fulfillment of a Promise?
then method of the Promise object
How do you handle the rejection of a Promise?
catch method of the Promise object