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

the . call

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

Describe method definition syntax (structure).

A

__name of method__ : function(__parameters__) {
–code–
}

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

Describe method call syntax (structure).

A

__name of obj__ . __name of method__(__args__)

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

it 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); taking related data and functionality and putting them together in an 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

being able to work with complex things in a simple way (ex: light switch, auto transmition in a car, the DOM); a simple interphase that does complex things behind the scenes (ie pushing the gas/brake on a car vs thinking about how the engine delivers power to the wheels, etc)

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 connect computers/pieces of software to each other

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

What is this in JavaScript?

A

this is an implicit property of an object that refers to the object itself; when unassigned to an object this = Window object

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 not explicitly defined (like a variable is), it ‘comes with’ the creation of the object; it is defined at the time of the method call

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

call time

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

character obj

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

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

A

you cant; defined at call time

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

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

A

find where the functionis called and look for the obj to the left of the dot

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

What kind of inheritance does the JavaScript programming language use?

A

prototype: objects inherit from other objects

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

What is a prototype in JavaScript?

A

an object that passes down properties

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

prototypal inheritance from the global objs

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

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

A

its prototype

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

What does the new operator do?

A

creates an instance from a constructor function

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

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

A

prototype

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

What does the instanceof operator do?

A

checks the prototype tree of an object to see if something is there

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

What is a “callback” function?

A

a function that is used as an argument for another function

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

setInterval()

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

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

A

setInterval( __function__ , __time (ms)_ )

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

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

A

0 ms

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

What do setTimeout() and setInterval() return?

A

numeric id for that timer

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

What is a client?

A

the client is the one that makes a request of a server (a person, cpu, app, etc)

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

What is a server?

A

provide data, service or function; receive requests –> send response

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

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

A

http method, request target, http version

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

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

A

protocol version, status code (ex 404), status text (explains in plain language what the code means)

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

What are HTTP headers?

A

specifies req or gives more info about body; meta-info about content, but not the content itself; case-sensitive string + colon + value (structure depends on header)

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

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

A

https://httpie.io/docs#usage

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

What is AJAX?

A

building webpages using XMLHttpRequest; allows you to update DOM w/out refreshing page

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
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
39
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
40
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
41
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 prototypally inherit the addEventListener() from the EventTarget class

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

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

A

a code block is a passage of code within a set of braces

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

What does block scope mean?

A

the code only applies to within a code block

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

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

A

block

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

What is the difference between let and const?

A

let can be reassigned; const cannot

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

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

A

because the address of the object does not change

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

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

A

determine if you need to reassign the variable or not

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

What is the syntax for writing a template literal?

A

a string wrapped in ` `

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

What is “string interpolation”?

A

subbing values of vars into strs

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

What is destructuring, conceptually?

A

simply assigning a property’s value to a variable

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

What is the syntax for Object destructuring?

A

let {__property name1__ , __property name2__} = __object__

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

What is the syntax for Array destructuring?

A

let [__var 1__ , __var2__ ] = __array__

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

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

A

the [ ] vs { }

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

What is the syntax for defining an arrow function?

A
const \_\_var\_\_ = ( \_\_para1\_\_, \_\_para2\_\_, ...) => {
\_\_\_\_\_code\_\_\_\_\_
return \_\_\_\_\_\_ }

OR

const __var__ = ( __para1__, __para2__, …) => ___code__

55
Q

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

A

you do not need a return statement

56
Q

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

A

it is determined at definition time (not call time); most likely the window object, except when it is assigned in a constructor function (then this = instance of constructor)

57
Q

What is a CLI?

A

command-line interfaces

58
Q

What is a GUI?

A

graphical user interface; visualizes CPU processes to make them understandable (ex: any CPU application)

59
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 : man __cmd name__ (ex. looking up what a command does)

cat : cat __things you want to print/combine separated by a space__ (ex. combining indiv chapters into a book)(uses: read contents of file, send contents to another CLI file; use ‘>’ at end of file list to save mult files into a single file)

ls : ls __dir you want to display__

pwd : pwd –> shows current/working dir

echo : echo __str that you want to print__ (uses: can print str to terminal, use ‘>’ to save str to a file)

touch : touch __file you want to change/access the time stamp of__

mkdir : mkdir __name of dir you want to make__

mv : mv -T __og name__ __new name__
mv __file__ __new dest__ (uses: changes file name)

rm : rm -r __dir to delete__
rm __file to delete__

cp: cp -T __file to copy__ __name of copy__

60
Q

What are the three virtues of a great programmer?

A

laziness, impatience, hubris

61
Q

What is Node.js?

A

a program that allows JS to be run outside of a web browser; used to build the back end; powered by V8

62
Q

What can Node.js be used for?

A

build the back end of web based apps, command-line programs, automation script

63
Q

What is a REPL?

A

read-evaluate-print loop; it is an interface that executes code in a piece-wise fashion

64
Q

When was Node.js created?

A

2009

65
Q

What back end languages have you heard of?

A

none

66
Q

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

A

global obj that provides info and control over the current node.js process

67
Q

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

A

declare ‘process’

68
Q

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

A

object

69
Q

What is a computer process?

A

an instance of a script

70
Q

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

A

158

71
Q

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

A

so you can manage other processes that may help/interfere with your code

72
Q

What is a JavaScript module?

A

a JS file

73
Q

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

A
(function(exports, require, module, \_\_filename, \_\_dirname) {
// Module code actually lives in here
});
74
Q

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

A

export and module

75
Q

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

A

to export functions to other modules

76
Q

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

A

with the require() function

77
Q

What is the JavaScript Event Loop?

A

the underlying part of JS that takes events and runs them when it’s appropriate; ‘after i run this chuck of synchronous code, what do i do next…what happens if the user interacts?…’

78
Q

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

A

blocking (synchronous): blocks any other piece of code from running while that code is running
non-blocking (asynchronous): the opposite of blocking (ex network req, slow operations that dont require a lot of effort)

79
Q

What is a directory?

A

a collection of files/modules

80
Q

What is a relative file path?

A

a file path that does not start at the root directory

81
Q

What is an absolute file path?

A

a file path that starts at the root directory

82
Q

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

A

fs

83
Q

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

A

fs.Writefile

84
Q

Are file operations using the fs module synchronous or asynchronous?

A

synchronous

85
Q

What is a client?

A

a requestor of a service

86
Q

What is a server?

A

the provider of a service or resource

87
Q

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

A

GET

88
Q

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

A

an HTTP method, a target and the lang of your request

89
Q

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

A

^^

90
Q

What are HTTP headers?

A

add extra information to the request (ie file formats, response format, etc)

91
Q

Is a body required for a valid HTTP message?

A

no

92
Q

What is NPM?

A

a way to create and share packages of reusable code that solve specific problems; dependency/package manager

93
Q

What is a package?

A

a portion of JS code

94
Q

How can you create a package.json with npm?

A

wit the ‘npm init –yes’ command

95
Q

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

A

a dependency is another package of code that is necessary to operate a npm package

adding the package as a property in the ‘dependencies’ (value = version number)

96
Q

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

A

it DLs with the package

97
Q

How do you add express to your package dependencies?

A

‘npm install __pkgName__ –save’

98
Q

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

A

express.listen(__port#__, __callback function__)

99
Q

How do you mount a middleware with an Express application?

A

the ‘use’ method

100
Q

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

A

req and res

101
Q

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

A

JSON

102
Q

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

A

it tells the server what the client wants to do and what service it needs to provide

103
Q

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

A

processes server requests before sending responses

104
Q

What is PostgreSQL and what are some alternative relational databases?

A

open sourced RDMS (relational database management system); MySQL, Microsoft SQL Server, & Oracle

105
Q

What are some advantages of learning a relational database?

A

learning how to use SQL

106
Q

What is one way to see if PostgreSQL is running?

A

using the “top” command in the Command Line

107
Q

What is a database schema?

A

a collection of tables in a database; defines columns, rules for data (type, potential values)

108
Q

What is a table?

A

a list of rows w/ common attributes (columns)

109
Q

What is a row?

A

an entity with attributes; an instance of the attributes in the columns

110
Q

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

A

Structured Query Language; it is a DECLARATIVE language (ie you describe the results and the environment comes up with how to do that)

111
Q

How do you retrieve specific columns from a database table?

A

use the ‘select’ keyword:
select “__name of col1__”,
“__name of col2__“,…
from “name of table”;

112
Q

How do you filter rows based on some specific criteria?

A

use ‘where’ keyword:
select “____“…
from “__name of table__”
where “name of col” = ‘value’;

113
Q

What are the benefits of formatting your SQL?

A

readability

114
Q

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

A

, =, !=

115
Q

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

A

use ‘limit’ keyword:

limit 10

116
Q

How do you retrieve all columns from a database table?

A

use ‘ * ‘:

select *

117
Q

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

A

‘order by’ keyword (+ asc or desc):

order by “col name” asc or desc

118
Q

How do you add a row to a SQL table?

A

‘insert’ keyword:
insert into table name (“col1”, ….)
values (‘col val 1’, …)

119
Q

What is a tuple?

A

an array for SQL

120
Q

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

A

use a comma separated list after ‘values’

121
Q

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

A

use ‘ returning * ‘

122
Q

How do you update rows in a database table?

A

‘update’ keyword

123
Q

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

A

it will update all vals of that column

124
Q

How do you delete rows from a database table?

A

use ‘delete’ keyword:
delete from “table name
where …

125
Q

How do you accidentally delete all rows from a table?

A

delete from “table name

126
Q

What is a foreign key?

A

an identifier that references data stored in another table

127
Q

How do you join two SQL tables?

A

after the ‘select’-‘from’ (before ‘where’) clauses:

join “table name” using (“common col name”)

128
Q

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

A

using aliasing: “actual name” as “alias

129
Q

What are some examples of aggregate functions?

A

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

130
Q

What is the purpose of a group by clause?

A

to take alike rows and collapse them to a single unit and run aggregate functions

131
Q

What are the three states a Promise can be in?

A

pending: initial state, neither fulfilled nor rejected.
fulfilled: meaning that the operation was completed successfully.
rejected: meaning that the operation failed.

132
Q

How do you handle the fulfillment of a Promise?

A

.then()

133
Q

How do you handle the rejection of a Promise?

A

.catch()