m-2-0522 Flashcards

1
Q

What is a method?

A

A method is a function which is a property of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can you tell the difference between a method definition and a method call?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe method definition syntax (structure).

A
var object = {
method: function () {
}
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe method call syntax (structure).

A

object.method();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How is a method different from any other function?

A

A method is a property of an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain both data (as properties) and behavior (as methods)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are the four “principles” of Object-Oriented Programming?

A

Abstraction
Encapsulation
Inheritance
Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does API stand for?

A

application programming interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the purpose of an API?

A

to give programmers a way to interact with a system in a simplified, consistent fashion

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is this in JavaScript?

A

the value of this is determined by how a function is called

this describes the current context you’re in

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does it mean to say that this is an “implicit parameter”?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

When is the value of this determined in a function; call time or definition time?

A

the value of this is determined when the function is called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
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);
  }
};
A

window object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

It’s-a-me, Mario!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
Given the above character object, what is the result of the following code snippet? Why?
var hello = character.greet;
hello();
A

It’s-a-me, undefined!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How can you tell what the value of this will be for a particular function or method definition?

A

we can’t

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How can you tell what the value of this is for a particular function or method call?

A

Find where the function is called and look for an object to the left of the dot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is a prototype in JavaScript?

A

a JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

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?

A

prototype-based inheritance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

If an object does not have it’s own property or method by a given key, where does JavaScript look for it?

A

prototype object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What does the new operator do?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

prototype property

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

What does the instanceof operator do?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is a “callback” function?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

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?

A

setTimeout()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What do setTimeout() and setInterval() return?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is a client?

A

a service requestor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is a server?

A

provider of a resource or service

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What three things are on the start-line of an HTTP request message?

A

HTTP method, request target, and HTTP version

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What three things are on the start-line of an HTTP response message?

A

The protocol version, a status code, a status text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What are HTTP headers?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

Where would you go if you wanted to learn more about a specific HTTP Header?

A

MDN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

Is a body required for a valid HTTP request or response message?

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What is AJAX?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

load

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

they have a shared prototype object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

What is a code block? What are some examples of a code block?

A

a group of zero or more statements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

What does block scope mean?

A

The current context of execution. The context in which values and expressions are “visible” or can be referenced.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

What is the scope of a variable declared with const or let?

A

block scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

What is the difference between let and const?

A

let can be updated but not re-declared.

const cannot be updated or re-declared.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Why is it possible to .push() a new value into a const variable that points to an Array?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

How should you decide on which type of declaration to use?

A

scope
reassignment
redeclaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

What is the syntax for writing a template literal?

A

To create a template literal, instead of single quotes ( ‘ ) or double quotes ( “ ) quotes we use the backtick ( ` ) character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

What is “string interpolation”?

A

the ability to substitute part of the string for the values of variables or expressions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

What is destructuring, conceptually?

A

unpack values from arrays, or properties from objects, into distinct variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

What is the syntax for Object destructuring?

A
const user = {
    id: 42,
    isVerified: true
};

const {id, isVerified} = user;

console. log(id); // 42
console. log(isVerified); // true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

What is the syntax for Array destructuring?

A

const foo = [‘one’, ‘two’, ‘three’];

const [red, yellow, green] = foo;

console. log(red); // “one”
console. log(yellow); // “two”
console. log(green); // “three”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

the object/array are on the left side or no side when creating
the object/array are on the right side when destructuring

56
Q

What is the syntax for defining an arrow function?

A

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;
}
57
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

expression vs statement

58
Q

How is the value of this determined within an arrow function?

A

an arrow function captures the this value of the enclosing context instead of creating its own this context

59
Q

What is a CLI?

A

command line interface

60
Q

What is a GUI?

A

graphical user interface

61
Q
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
A

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.

62
Q

What are the three virtues of a great programmer?

A

laziness, impatience, hubris

63
Q

What is Node.js?

A

Node.js is a program that allows JavaScript to be run outside of a web browser.

64
Q

What can Node.js be used for?

A

It is commonly used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.

65
Q

What is a REPL?

A

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.

66
Q

When was Node.js created?

A

May 27, 2009

67
Q

What back end languages have you heard of?

A

Python, Java

68
Q

What is the process object in a Node.js program?

A

The process object is a global that provides information about, and control over, the current Node.js process.

69
Q

How do you access the process object in a Node.js program?

A

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’);

70
Q

What is the data type of process.argv in Node.js?

A

string type

71
Q

What is a computer process?

A

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.

72
Q

Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?

A

134 processes

73
Q

Why should a full stack Web developer know that computer processes exist?

A

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.

74
Q

What is a JavaScript module?

A

In JavaScript, a “module” is a single .js file.

75
Q

What values are passed into a Node.js module’s local scope?

A

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.

76
Q

Give two examples of truly global variables in a Node.js program.

A

console and process

77
Q

What is the purpose of module.exports in a Node.js module?

A

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.

78
Q

How do you import functionality into a Node.js module from another Node.js module?

A

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.

79
Q

What is the JavaScript Event Loop?

A

The event loop is a constantly running process that monitors both the callback queue and the call stack.

80
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

Blocking methods execute synchronously and non-blocking methods execute asynchronously.

81
Q

What is a directory?

A

In computing, a directory is a file system cataloging structure which contains references to other computer files, and possibly other directories.

82
Q

What is a relative file path?

A

Relative Path is the hierarchical path that locates a file or folder on a file system starting from the current directory.

83
Q

What is an absolute file path?

A

An absolute path always contains the root element and the complete directory list required to locate the file.

84
Q

What module does Node.js include for manipulating the file system?

A

fs module

85
Q

What method is available in the Node.js fs module for writing data to a file?

A

writeFile method

86
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

87
Q

What is a client?

A

service requestor

88
Q

What is a server?

A

provider of a resource or service

89
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

get

90
Q

What is on the first line of an HTTP request message?

A

http method, request target, http version

91
Q

What is on the first line of an HTTP response message?

A

protocol version, status code, status text

92
Q

What are HTTP headers?

A

additional information passed by the client and/or server with an HTTP request or HTTP response

93
Q

Is a body required for a valid HTTP message?

A

no

94
Q

What is NPM?

A

node package manager

npm is the world’s largest software registry

95
Q

What is a package?

A

a directory with one or more files in it that also has a file called package.json with some metadata about the package

96
Q

How can you create a package.json with npm?

A

npm init

97
Q

What is a dependency and how to you add one to a package?

A

A dependency is a library that a project needs to function effectively
npm install [ …]

98
Q

What happens when you add a dependency to a package with npm?

A

you can use that code with your code

99
Q

How do you add express to your package dependencies?

A

$ npm install express

100
Q

What Express application method starts the server and binds it to a network PORT?

A

the listen() method

101
Q

How do you mount a middleware with an Express application?

A

calling the use method of the Express application object

102
Q

Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

the req object and the res object

103
Q

What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?

A

application/json; charset=utf-8

104
Q

What is the significance of an HTTP request’s method?

A

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

105
Q

What does the express.json() middleware do and when would you need it?

A

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.

106
Q

What is PostgreSQL and what are some alternative relational databases?

A

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.

107
Q

What are some advantages of learning a relational database?

A

relational databases are good at storing related data and support good guarantees about data integrity

108
Q

What is one way to see if PostgreSQL is running?

A

sudo service postgresql status

109
Q

What is a database schema?

A

A collection of tables

110
Q

What is a table?

A

A table is a list of rows each having the same set of attributes.

111
Q

What is a row?

A

a record of data

112
Q

What is SQL and how is it different from languages like JavaScript?

A

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.

113
Q

How do you retrieve specific columns from a database table?

A

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.

114
Q

How do you filter rows based on some specific criteria?

A
select "productId",
       "name",
       "price"
  from "products"
 where "category" = 'cleaning';
115
Q

What are the benefits of formatting your SQL?

A

SQL does not have to be indented, but you should do it anyway for consistent style and therefore readability.

116
Q

What are four comparison operators that can be used in a where clause?

A

Other comparisons like <, >, and != are available too

117
Q

How do you limit the number of rows returned in a result set?

A
select "name",
       "description"
  from "products"
 order by "price" desc
 limit 1;
118
Q

How do you retrieve all columns from a database table?

A

select *

from “products”;

119
Q

How do you control the sort order of a result set?

A

select *
from “products”
order by “price”;

120
Q

How do you add a row to a SQL table?

A

insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’);

121
Q

What is a tuple?

A

a list of values

122
Q

How do you add multiple rows to a SQL table at once?

A

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 *;

123
Q

How do you get back the row being inserted into a table without a separate select statement?

A

returning clause

124
Q

How do you update rows in a database table?

A

update “products”

set “price” = 100;

125
Q

Why is it important to include a where clause in your update statements?

A

to only target specific rows

126
Q

How do you delete rows from a database table?

A

delete from “products”
where “productId” = 24
returning *;

127
Q

How do you accidentally delete all rows from a table?

A

delete from “products”;

128
Q

What is a foreign key?

A

an attribute that links to another table

129
Q

How do you join two SQL tables?

A

select *
from “products”
join “suppliers” using (“supplierId”);

130
Q

How do you temporarily rename columns or tables in a SQL statement?

A

select “products”.”name” as “product”,
“suppliers”.”name” as “supplier”
from “products”
join “suppliers” using (“supplierId”);

131
Q

What are some examples of aggregate functions?

A

max(), avg(), count(), min(), sum(), every()

takes a list of values and creates a single value

132
Q

What is the purpose of a group by clause?

A

to separate rows into groups and perform aggregate functions on those groups of rows

133
Q

What are the three states a Promise can be in?

A

pending
fulfilled
rejected

134
Q

How do you handle the fulfillment of a Promise?

A

then method of the Promise object

135
Q

How do you handle the rejection of a Promise?

A

catch method of the Promise object