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
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?
setInterval()
26
How can you set up a function to be called repeatedly without using a loop?
setInterval( __function__ , __time (ms)_ )
27
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 ms
28
What do setTimeout() and setInterval() return?
numeric id for that timer
29
What is a client?
the client is the one that makes a request of a server (a person, cpu, app, etc)
30
What is a server?
provide data, service or function; receive requests --> send response
31
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
32
What three things are on the start-line of an HTTP request message?
http method, request target, http version
33
What three things are on the start-line of an HTTP response message?
protocol version, status code (ex 404), status text (explains in plain language what the code means)
34
What are HTTP headers?
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)
35
Where would you go if you wanted to learn more about a specific HTTP Header?
https://httpie.io/docs#usage
36
Is a body required for a valid HTTP request or response message?
no
37
What is AJAX?
building webpages using XMLHttpRequest; allows you to update DOM w/out refreshing page
38
What does the AJAX acronym stand for?
asynchronous javascript and xml
39
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest()
40
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
41
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
they prototypally inherit the addEventListener() from the EventTarget class
42
What is a code block? What are some examples of a code block?
a code block is a passage of code within a set of braces
43
What does block scope mean?
the code only applies to within a code block
44
What is the scope of a variable declared with const or let?
block
45
What is the difference between let and const?
let can be reassigned; const cannot
46
Why is it possible to .push() a new value into a const variable that points to an Array?
because the address of the object does not change
47
How should you decide on which type of declaration to use?
determine if you need to reassign the variable or not
48
What is the syntax for writing a template literal?
a string wrapped in ` `
49
What is "string interpolation"?
subbing values of vars into strs
50
What is destructuring, conceptually?
simply assigning a property's value to a variable
51
What is the syntax for Object destructuring?
let {__property name1__ , __property name2__} = __object__
52
What is the syntax for Array destructuring?
let [__var 1__ , __var2__ ] = __array__
53
How can you tell the difference between destructuring and creating Object/Array literals?
the [ ] vs { }
54
What is the syntax for defining an arrow function?
``` const __var__ = ( __para1__, __para2__, ...) => { _____code_____ return ______ } ``` OR const __var__ = ( __para1__, __para2__, ...) => ___code__
55
When an arrow function's body is left without curly braces, what changes in its functionality?
you do not need a return statement
56
How is the value of this determined within an arrow function?
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
What is a CLI?
command-line interfaces
58
What is a GUI?
graphical user interface; visualizes CPU processes to make them understandable (ex: any CPU application)
59
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 : 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
What are the three virtues of a great programmer?
laziness, impatience, hubris
61
What is Node.js?
a program that allows JS to be run outside of a web browser; used to build the back end; powered by V8
62
What can Node.js be used for?
build the back end of web based apps, command-line programs, automation script
63
What is a REPL?
read-evaluate-print loop; it is an interface that executes code in a piece-wise fashion
64
When was Node.js created?
2009
65
What back end languages have you heard of?
none
66
What is the process object in a Node.js program?
global obj that provides info and control over the current node.js process
67
How do you access the process object in a Node.js program?
declare 'process'
68
What is the data type of process.argv in Node.js?
object
69
What is a computer process?
an instance of a script
70
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
158
71
Why should a full stack Web developer know that computer processes exist?
so you can manage other processes that may help/interfere with your code
72
What is a JavaScript module?
a JS file
73
What values are passed into a Node.js module's local scope?
``` (function(exports, require, module, __filename, __dirname) { // Module code actually lives in here }); ```
74
Give two examples of truly global variables in a Node.js program.
export and module
75
What is the purpose of module.exports in a Node.js module?
to export functions to other modules
76
How do you import functionality into a Node.js module from another Node.js module?
with the require() function
77
What is the JavaScript Event Loop?
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
What is different between "blocking" and "non-blocking" with respect to how code is executed?
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
What is a directory?
a collection of files/modules
80
What is a relative file path?
a file path that does not start at the root directory
81
What is an absolute file path?
a file path that starts at the root directory
82
What module does Node.js include for manipulating the file system?
fs
83
What method is available in the Node.js fs module for writing data to a file?
fs.Writefile
84
Are file operations using the fs module synchronous or asynchronous?
synchronous
85
What is a client?
a requestor of a service
86
What is a server?
the provider of a service or resource
87
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
88
What is on the first line of an HTTP request message?
an HTTP method, a target and the lang of your request
89
What is on the first line of an HTTP response message?
^^
90
What are HTTP headers?
add extra information to the request (ie file formats, response format, etc)
91
Is a body required for a valid HTTP message?
no
92
What is NPM?
a way to create and share packages of reusable code that solve specific problems; dependency/package manager
93
What is a package?
a portion of JS code
94
How can you create a package.json with npm?
wit the 'npm init --yes' command
95
What is a dependency and how to you add one to a package?
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
What happens when you add a dependency to a package with npm?
it DLs with the package
97
How do you add express to your package dependencies?
'npm install __pkgName__ --save'
98
What Express application method starts the server and binds it to a network PORT?
express.listen(__port#__, __callback function__)
99
How do you mount a middleware with an Express application?
the 'use' method
100
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req and res
101
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
JSON
102
What is the significance of an HTTP request's method?
it tells the server what the client wants to do and what service it needs to provide
103
What does the express.json() middleware do and when would you need it?
processes server requests before sending responses
104
What is PostgreSQL and what are some alternative relational databases?
open sourced RDMS (relational database management system); MySQL, Microsoft SQL Server, & Oracle
105
What are some advantages of learning a relational database?
learning how to use SQL
106
What is one way to see if PostgreSQL is running?
using the "top" command in the Command Line
107
What is a database schema?
a collection of tables in a database; defines columns, rules for data (type, potential values)
108
What is a table?
a list of rows w/ common attributes (columns)
109
What is a row?
an entity with attributes; an instance of the attributes in the columns
110
What is SQL and how is it different from languages like JavaScript?
Structured Query Language; it is a DECLARATIVE language (ie you describe the results and the environment comes up with how to do that)
111
How do you retrieve specific columns from a database table?
use the 'select' keyword: select "__name of col1__", "__name of col2__",... from "_name of table_";
112
How do you filter rows based on some specific criteria?
use 'where' keyword: select "____"... from "__name of table__" where "_name of col_" = '_value_';
113
What are the benefits of formatting your SQL?
readability
114
What are four comparison operators that can be used in a where clause?
, =, !=
115
How do you limit the number of rows returned in a result set?
use 'limit' keyword: | limit 10
116
How do you retrieve all columns from a database table?
use ' * ': | select *
117
How do you control the sort order of a result set?
'order by' keyword (+ asc or desc): order by "_col name_" asc or desc
118
How do you add a row to a SQL table?
'insert' keyword: insert into _table name_ ("_col1_", ....) values ('_col val 1_', ...)
119
What is a tuple?
an array for SQL
120
How do you add multiple rows to a SQL table at once?
use a comma separated list after 'values'
121
How do you get back the row being inserted into a table without a separate select statement?
use ' returning * '
122
How do you update rows in a database table?
'update' keyword
123
Why is it important to include a where clause in your update statements?
it will update all vals of that column
124
How do you delete rows from a database table?
use 'delete' keyword: delete from "_table name_" where ...
125
How do you accidentally delete all rows from a table?
delete from "_table name_"
126
What is a foreign key?
an identifier that references data stored in another table
127
How do you join two SQL tables?
after the 'select'-'from' (before 'where') clauses: | join "_table name_" using ("_common col name_")
128
How do you temporarily rename columns or tables in a SQL statement?
using aliasing: "_actual name_" as "_alias_"
129
What are some examples of aggregate functions?
avg() ; sum() ; max() ; min() ; count() ; every() ;
130
What is the purpose of a group by clause?
to take alike rows and collapse them to a single unit and run aggregate functions
131
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.
132
How do you handle the fulfillment of a Promise?
.then()
133
How do you handle the rejection of a Promise?
.catch()