Module 2 Flashcards

1
Q

What is a method?

A

A function that 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

Function definition has structure function () { }, a call just has the function name and parameters, empty if none.

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

Describe method definition syntax (structure).

A

an object, function keyword, parenthese for arguments, and codeblock

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

Describe method call syntax (structure).

A

object.methodName()

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

Stored as 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). You wrap functionality with the data structure (object).

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

Simplifying a complex action into a simple one

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

A software interface that offers services to other software. A way for one software to use another software’s data without having to know how the other software works. Like going to a restaurant and ordering food, you don’t need to know how to make it or how to request the chef, just need to know what you want.

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

What is this in JavaScript?

A

An implicit parameter that changes depending on where in a function it is called. Usually refers to what object you are 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

It is something available to use in a code block even if it was never explicitly declared or included in its parameter list.

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

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

the character 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!’ Because it calls the method in the object, which calls for a string plus the object firstName property with this.

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!’ Because ‘this’ refers to window since it is not directing to any object. Hello is only assigned the function greet, no connection to character object.

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

Impossible to tell because this is defined by when it is called. You can make a best guess if it is a method.

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

Prototypal (prototype-based). Objects inherit from other objects.
Trivia: Most other programming languages are class-based, they inherit from classes rather than objects.

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

What is a prototype in JavaScript?

A

Template that objects inherit properties and methods from

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 objects, arrays, and numbers?

A

It has an existing prototype object in javascript

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

it checks the first prototype then checks the prototype of that prototype and so on, until it finds it, or returns undefined.

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

What does the new operator do?

A

It creates a new empty object then assigns that object’s prototype to be the prototype property of the constructor, then calls the constructor function assigning ‘this’, and if there is no return object for the function it uses ‘this’.

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. Note that function objects have their own properties that can be found. 5 total properties, see MDN.

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

What does the instanceof operator do?

A

Checks if the prototype property of a constructor appears anywhere in the prototype chain of the object.

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

What is a “callback” function?

A

A function passed into another function as an argument

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() or setInterval().

Related ones: getAnimationFrame() and requestIdleCallback(), which adjust to how fast browser is running.

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

No delay. However, it is still asynchronous and anything without setTimeout() or setInterval() will run after anything that is not timed.

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

What do setTimeout() and setInterval() return?

A

an integer ID number which can be passed into clearTimeout()

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

What is a client?

A

The one that requests a service

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

What is a server?

A

Provider of resources or services to clients

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 method by default

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

The method, path aka the request target, and the http method (protocol version).
Example format: PUT /create_page HTTP/1.1

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 http method (protocol version), status code (success or fail, 404 is a notable example), and status text description

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

What are HTTP headers?

A

They let the client or server pass additional information with a http request or response.

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, developer.mozilla.org/en-US/docs/Web/HTTP/Headers

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. Request typically does not contain body. Response does not necessarily always have a body.

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

What is AJAX?

A

A technique for loading data into part of a page without having to reload an entire page.

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

xmlhttpRequest()?

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’ event

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

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

A

It inherited this object prototype property?

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

What is destructuring, conceptually?

A

Turning the properties of an object or values of an array into individual variables

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

What is the syntax for Object destructuring?

A

let { property1: variable1, property2: variable2 } = object;

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

What is the syntax for Array destructuring?

A

let [ arrayItem1, arrayItem2, …args ] = arrayName;

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

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

A

destructuring is like a reverse of creating, appears like it is declaring the object or array first then assigning to a variable name.

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

What is the syntax for defining an arrow function?

A

(argument) => { argument function } or () => return or no parentheses for just one argument.

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

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

A

The end result is returned automatically without a return statement.

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

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

A

Determined at definition, unlike function keyword which determines at function call.

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

What is Node.js?

A

Program that runs JavaScript outside of a browser, powered by v8 the same as Chrome. it is wrapped in various apis that allow it to interact with the host operating system. Browser JS is very limited, aka “sandboxed” to browser. It is an application server and can run programs that do not need to be in a web browser.

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

What can Node.js be used for?

A

To build back ends for web applications, command line programs, run web servers, write desktop applications, write mobile applications, or any other automation.

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

What is a REPL?

A

Read–eval–print loop. 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. Read means it interprets user input. Eval means it runs whatever the user inputs. Print means it returns a value, so it is undefined if nothing is specified. Loop means it can be done again afterwards.

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

When was Node.js created?

A

May 27 2009. Note how recent it is. But also this is long enough to be considered middle aged for a program.

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

What back end languages have you heard of?

A

JavaScript, Java, Python, C, C++, C#? Web backend: Node, PHP, Ruby. Most recent: Rust (Not specifically web, just improved C++)

56
Q

What is a computer process?

A

Instance of computer program being executed by one or multiple threads.

57
Q

What is a CLI?

A

Command Line Interface. Advantage: More control for automating and direct instructions. More computer and programmer friendly.

58
Q

What is a GUI?

A

Graphic User Interface

59
Q

Use of command line man

A

manual

60
Q

Use of command line cat

A

concatenates file

61
Q

Use of command line ls

A

lists files in directory

62
Q

Use of command line pwd

A

print working directory

63
Q

Use of command line man

A

Prints whatever you enter into terminal

64
Q

Use of command line touch

A

Update when file was modified

65
Q

Use of command line mkdir

A

Makes a new directory

66
Q

Use of command line mv

A

Moves file or folder

67
Q

Use of command line rm

A

Removes (deletes) file or folder. Add -r to recursively remove nested directories and their contents as well. -f forces it to do it all without confirming.

68
Q

Use of command line cp

A

Copy file or folder

69
Q

What are the three virtues of a great programmer?

A
  1. 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.
  2. 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.
  3. Hubris: The quality that makes you write (and maintain) programs that other people won’t want to say bad things about.
70
Q

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

A

A lot- over 100.

71
Q

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

A

Most importantly so that you can kill a process if needed. See what ports are being taken up by a process, because one port can only be used by one webserver at a time. To be able to take full advantage of what can be done and to be aware of limitations.

72
Q

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

A

Provides information about the current node process.

73
Q

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

A

Console.log(process); the variable name process.

74
Q

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

A

An array of all modules.

75
Q

What is a JavaScript module?

A

A single js file with its own scope.

76
Q

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

A

exports, require, module, __filename, and __dirname

77
Q

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

A

Buffer, console, process

78
Q

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

A

It is the placeholder of what is returned from the module, specifies what you want to be available for another module to use

79
Q

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

A

Use the require() function with the module name.

80
Q

What is the JavaScript event loop?

A

The way JavaScript treats processes which is with a queue of tasks that need to be completed before the next. First takes task, adds its code to call stack, resolves the stack, finishes the task, and takes it off the queue.

81
Q

What is the difference between ‘blocking’ and ‘non-blocking’ code?

A

blocking vs nonblocking is like synchronous or asynchronous code. Blocking must be executed and finished one by one and will prevent the next from happening. Non blocking will start it, let code afterwards get added to task queue run, and if it finishes it is added back to task queue.

82
Q

What is a directory?

A

The folder/file that points to other files.

83
Q

What is a relative file path?

A

The location of the file relative to the current directory folder

84
Q

What is an absolute file path?

A

The full directory file location starting from root element to end target file.

85
Q

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

A

fs module, aka file system.

86
Q

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

A

fs.readFile

87
Q

Are file operations of the fs module synchronous or asynchronous

A

Asynchronous

88
Q

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

A

GET method

89
Q

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

A

The http method, request target, and html version

90
Q

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

A

The protocol version, status code, and status text that is meant for a human to understand

91
Q

What are HTTP headers?

A

Lets client and server pass additional information in the request or response. It’s usually meta information as key-value pairs.

92
Q

What is NPM?

A

Node package manager, a way to upload, share, or download modules (aka packages) of code. Large software registry, and has command line interface.

93
Q

What is a package?

A

A self contained collection of files that are needed or included for a library. Packages tend to contain multiple modules.

94
Q

How can you create a package.json with npm?

A

Within the directory you want to create the json, type “npm init –yes” (notes -yes automatically says yes to all questions, should review next time if plan on publishing)

95
Q

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

A

It’s another package that your code needs. Installing another module into your project directory and turning that directory into a package.

96
Q

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

A

It gets added to package.json and downloads the package for that dependency and adds it to the modes module, and also all of its own dependencies.

97
Q

How do you add express to your package dependencies?

A

npm install express

98
Q

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

A

listen(portNumber). Calling listen is what tells it to start receiving and responding to requests. Can’t do anything to a server before that. Before this it is not really a server just software that’s running.

99
Q

How do you mount a middleware with an Express application?

A

Use app.method when express is imported and called and assigned to a variable app. Pass it a callback function with parameters req and res.

100
Q

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

A

req (request) and res (response)

101
Q

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

A

application/json; chartset=utf-8

102
Q

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

A

It indicates the desired action to be performed on the identified source.

103
Q

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

A

It allows the server to parse json and is needed if the body information that you’re sending and receiving are json format.

104
Q

What are the http request methods?

A

get, post delete, put, patch

105
Q

What is PostgreSQL and what are some alternative relational databases?

A

It is a relational database system (sql standing for structured query language). Others: MySQL, Microsoft Server, Oracle

106
Q

What are some advantages of learning a relational database?

A

It has a long history and SQL databases are widely used, they are flexible, harder to make accidental changes, they can model data, maintain quality of stored data integrity

107
Q

What is one way to see if PostgreSQL is running?

A

sudo service postgresql status, or top and see if it is running.

108
Q

What is a database schema?

A

The collection of tables in a database and definitions of the tables like columns, but not the data within the tables.

109
Q

What is a table?

A

The way data is stored in a relational database, which is a collection of rows that all have same set of attributes.

110
Q

What is a row?

A

Single record in a table.

111
Q

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

A

It stands for structured query language and it is a way of interacting with relational databases. The difference is that it is declarative rather than imperative. You tell it what you want done, rather than tell it exactly what to do and how.

112
Q

How do you retrieve specific columns from a database table?

A

You use the select declaration: select “columnName” from “tableName”

113
Q

How do you filter rows based on some specific criteria?

A

You add the where declaration: where “condition” = ‘value’

114
Q

What are the benefits of formatting your SQL?

A

Easier readability

115
Q

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

A

greater than, less than, equal to, and not equal to.

116
Q

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

A

Declare: limit number;

117
Q

How do you retrieve all columns from a database table?

A

Declare: select *

118
Q

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

A

Declare: order by “columnName” desc (default is ascending, descending is option to change order)

119
Q

How do you add a row to a SQL table?

A

You declare: insert into “tableName” (columnName, etc.) values (‘columnValue, etc’)

120
Q

What is a tuple?

A

List of values in a column with a fixed length, size, and meaning.

121
Q

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

A

Same as insert but add more values: values (‘columnValue1’), (‘columnValue2’)

122
Q

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

A

Declare “returning *” at the end of inserting. to specify, do returning (value1, value2)

123
Q

How do you update rows in a database table?

A

Declare: update “tableName” set “columnItem” = ‘newValue’. Note this updates everything

124
Q

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

A

So that you only update what you intend to and not the entire column in a table.

125
Q

How do you delete rows from a database table?

A

Declare: delete from “tableName”

126
Q

How do you accidentally delete all rows from a table?

A

Declaring delete from table without setting any restrictions on what to specifically delete

127
Q

What is a foreign key?

A

A column with values that refer to a column in another table with the same column name

128
Q

How do you join two SQL tables?

A

Declare: join “otherTable” using (“sharedColName”)

129
Q

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

A

Using “as”, declare: … “tableName” as “t”; OR “columnName” as “newName”. Alternatively: JOIN… ON… which uses multiple columns

130
Q

How do you change which rows limit picks up?

A

offset declaration: tells it to skip the number then take rows afterwards.

131
Q

What is a CRUD operation?

A

Create, read, update, delete

132
Q

What are some examples of aggregate functions?

A

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

133
Q

What is the purpose of a group by clause?

A

Tells the aggregate function how it should split its calculations among the rows

134
Q

What are the three states that a promise can be in?

A

Pending: something that takes a while, not necessarily a request. Resolved: normal response. Rejected: Error returned

135
Q

How do you handle the fulfilment of a promise?

A

Use then() method and a function as the first parameter, which runs when promise is resolved.

136
Q

How do you handle the rejection of a Promise?

A

Can either use then() method with a function as the second argument, or use catch().