Module 2 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

Methods are defined within the object literal in a series of function definitions, a method is called as a property of the object called when optional parameters are included in the parenthesis

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

Describe method definition syntax (structure).

A

Methods are defined in the object literal using a method name : function (parameters) { code block for function definition }

or using the dot notation and assigning it a value
can see that there is a defined body to that method

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(parameters);

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 attached to an object and must be called as a method of the object that describes the behavior of the object (property of the 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 contain both data (properties) and behavior (methods)
take related data and functionality and wrap them together in something called 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
  1. Abstraction
  2. Encapsulation
  3. Inheritance
  4. Polymorphism

would add a fifth called XYZ

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

What is “abstraction”?

A

the most important part of the term “abstraction” boils down to being able to work with (possibly) complex things in simple ways.

wrapping complex tasks in simple interfaces

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

the purpose of every software API is to give programmers a way to interact with a system in a simplified, consistent fashion: aka, an abstraction

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 of all javascript functions

a JS keyword that references the current 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

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

implied parameter - changed based on how you call the method but it is implied bc you don’t actually list it out in the parameter list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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 this refers to the character object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
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 the function is not being called with the object this is referring to to the left of the dot

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 cannot, you can only tell the value of this when the function is called

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 the function is not being called with the object this is referring to to the left of the dot

because this then refers to the window, not the 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

You cannot, you can only tell the value of this when the function is called

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

Look for an object to the left of the dot and if there is none, it will default to the window object

if not in the global scope, it will be undefined

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

What is a prototype in JavaScript?

A

an object that contains primarily methods and properties that can be used by other 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

an object that contains primarily methods and properties that can be used by other objects

property lookup on an object if the object doesn’t have it, it looks to that object’s prototype to see if that has the property

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

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

A

to the prototype object

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

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

A

to the prototype of the current 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
  1. Creates a blank, plain JavaScript object.
  2. Adds a property to the new object (__proto__) that links to the constructor function’s prototype object
  3. Binds the newly created object instance as the this context (i.e. all references to this in the constructor function now refer to the object created in the first step).
  4. Returns this if the function doesn’t return an object.
  5. Creates a blank object
  6. Sets that object’s prototype (__proto__) to equal the prototype property of the function it is called on (constructor)
  7. Runs the constructor function with ‘this’ that referring to new object
  8. Returns the return value of the function or the constructor function or if undefined, gives you back that new object
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

__proto__

prototype property

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
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. The instanceof operator tests the presence of constructor.prototype in object's prototype chain. Allows you to check if an object is an instance of a constructor
26
What is a "callback" function?
a function passed into another function as an argument
27
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(callbackfunction, delayInMiliseconds)
28
How can you set up a function to be called repeatedly without using a loop?
setInterval(callbackfunction, delayInMiliseconds) | clearInterval(Integer that corresponds to your result value from setInterval call)
29
What is a client?
hardware or software that is requesting functionality or services
30
What is a server?
a hardware or software that provides functionality for other programs or devices
31
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
32
What three things are on the start-line of an HTTP request message?
1. method 2. target - specified by the URL (not the entire one, it's the absolute path) 3. version
33
What three things are on the start-line of an HTTP response message?
1. version - of the http (1.1 or 1.0) 2. status code 3. status test
34
What are HTTP headers?
allow the client and the server to pass additional information meta information / not the core data extra contextual information (i.e. head tag of an HTML document)
35
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN i.e. content-type header can search on MDN by convention, custom headers start with an X
36
Is a body required for a valid HTTP request or response message?
no, it is optional for both
37
httPie
tool for performing raw http requests (without a browser)
38
What is AJAX?
a technique for loading data into the page without having to refresh the page
39
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML (acronym for the technologies used in asynchronous requests) XML = extensive markup language (extension of HTML where there is no limit for tag names, used as an interchange format, before JSON used for sending raw data back and forth)
40
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
41
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
42
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
there is an EventTarget prototype object that is the prototype of the XMLHttpRequest that has the addEventListener method both DOM elements and XMLHttpRequest objects inherit the method from the same prototype (EventTarget) that does have that method
43
What is a code block? What are some examples of a code block?
a code block is denoted by {} and typically stems from a conditional statement i.e. if, if else, else, for, while, try
44
What does block scope mean?
the scope of the variable is local to the code block which it was initialized in
45
What is the scope of a variable declared with const or let?
block scope
46
What is the difference between let and const?
with const, variable is read-only reference to a value | can't reassign the variable but can change the internals of it
47
Why is it possible to .push() a new value into a const variable that points to an Array?
because it is not directly redefining the array, since it is pointing to the array, you can manipulate it with the given methods .push & .pop but you cannot re-initialize the whole array variable to new values
48
How should you decide on which type of declaration to use?
depends on use case
49
What is the syntax for writing a template literal?
using back ticks
50
What is "string interpolation"?
substituting part of the string with a variable | concept, javascript template literal is an example of this
51
What is destructuring, conceptually?
destructuring allows you to assign properties of an object or elements of arrays to individual variables by flipping the literal on its head can select multiple properties or indexes in the same statement opposite of structuring - filling it with data destructing is reverse - pulling data out of it
52
What is the syntax for Object destructuring?
let {property1: variable1, property2: variable2, property3:variable3} = Object
53
What is the syntax for Array destructuring?
let [variable1, variable2, variable3] = Array
54
How can you tell the difference between destructuring and creating Object/Array literals?
destructuring is similar syntax, but flipped on its head. You assign the already declared object or array to the newly declared variables directly defined in the literal & its properties or elements
55
What is the syntax for defining an arrow function?
(parameters) => expression | (parameters) => { statements}
56
When an arrow function's body is left without curly braces, what changes in its functionality?
the return value of the expression is returned. you do not need to specify the return keyword
57
How is the value of this determined within an arrow function?
Arrow function captures the this value of the enclosing context instead of creating its own this context / more localized
58
What is a CLI?
Command Line Interface | terminal where you input text commands and it executes stuff
59
What is a GUI?
Graphic User Interface graphics base operating interface IDEs something that is optimized for humans to use (window, has text, has images, can have audio, can interact with the mouse, you can type on it)
60
``` 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 if you wanted to read through a specific command to see how it is used you can run through the terminal manual to find what it is about cat = concatentate to concatenate and print files on the terminal if you want to see 3 files printed side by side in the terminal ls = list lists out files of working directory pwd = print the name of the current working directory echo = display a line of text touch = change file timestamps mkdir = make directories mv = move or rename files rm = removes files or directories cp = copy source files & directories
61
What is Node.js?
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Allows the context to be expanded to servers outside of the browser so that you can use JS in context expanded from just the DOM ripped out of the browser surrounded by an API that allows V8 to work, including web servers Node.js is a program that allows JavaScript to be run outside of a web browser
62
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.
63
What is a REPL?
Read–eval–print loop a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the use - similar to a console.log
64
When was Node.js created?
2009
65
What back end languages have you heard of?
Python, C++, C#, Java, Ruby, PHP, Perl
66
What is a computer process?
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. it is an instance of the program which contains a task list/list of instructions to execute that has been copied from disk to memory (RAM) and then executed by the CPU via one or more threads
67
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
a lot, about 200-300+
68
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. Especially when working with applications made of multiple components, such as clients, servers, and databases. ``` Tier 3 application: client process server process database process so you can kill them - sometimes you need to kill the ones you don't want to run & can stop them from running ```
69
What is the process object in a Node.js program?
a global object that provides information about the current Node.js process & control over it all of the info about the currently running process
70
How do you access the process object in a Node.js program?
global so you can access just by calling process | can also call the require function with the 'process' argument
71
What is the data type of process.argv in Node.js?
array of strings containing command line arguments
72
What is a JavaScript module?
The whole idea behind modular programming is to decompose a solution to a large problem into many smaller solutions to sub-problems. ``` a way of breaking javascript code into multiple files their scope is module scope (they each have their own local scope) ```
73
What values are passed into a Node.js module's local scope?
``` __dirname __filename exports module require ``` way loads modules, loads the raw string from the file & wraps it in in a wrapper & provides a unique value to the module with those 5 things
74
Give two examples of truly global variables in a Node.js program.
console process setTimeOut setInterval
75
What is the purpose of module.exports in a Node.js module?
helps to share functions or variables between files
76
How do you import functionality into a Node.js module from another Node.js module?
``` module.exports var variable = require('path to module/module name') imports / export keywords ```
77
What is the JavaScript Event Loop?
checks the stack and the task queue and if the stack is empty, moves the first item in the task queue to the stack to be executed
78
What is different between "blocking" and "non-blocking" with respect to how code is executed?
blocking is when code takes a really long time to execute bc JS can only do one thing at a time since it runs on a single thread non-blocking is in reference to multi thread or asynchronous runtime behaviors operations that block for executions until previous is complete = synchronous operations that do not wait for other functions to execute = asynchronous runs alongside and then gets added at the end
79
difference between exports and module.export
``` initially they both point to the same object module.exports = { } var exports = module.exports ``` if you reassign exports variable to another value, the exports won't refer to the module.exports anymore exports is shorthand but module.exports is the authoritative - if you completely reassign, you have to go with module.exports
80
What is a directory?
a folder houses a list of file names that it contains and points to the files themselves (pointer to the actual files, not the actual files)
81
What is a relative file path?
a shorthand for a path within the same root directory ./dir ../parentdir filename or dir
82
What is an absolute file path?
the full path starting with the root of the file system to the corresponding file /home... ~/ starting from the home directory of the current user (shorthand for /home/username)
83
What module does Node.js include for manipulating the file system?
File System Module (fs)
84
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile
85
fs.write file is synchronous or asynchronous?
asynchronous
86
What is a client?
computer hardware or software that accesses services made available by a server makes requests to a server and interprets their responses
87
What is a server?
computer hardware or software that provides data or functionality to a client listens for network requests and responds to them
88
Which HTTP method does a browser issue to a web server when you visit a URL?
GET | can go to the network tab and see the the request types
89
What is on the first line of an HTTP request message?
Start line with your: 1. HTTP method i.e. GET, PUT, POST 2. Request Location URL 3. HTTP Protocol Version
90
What is on the first line of an HTTP response message?
1. HTTP Protocol Version 2. Status Code - 404, 302, or 200 3. Status Descriptor (brief descriptor of the status code)
91
What are HTTP headers?
HTTP headers let the client and the server pass additional information with an HTTP request or response. Request headers contain more information about the resource to be fetched, or about the client requesting the resource. Response headers hold additional information about the response, like its location or about the server providing it. the headers refers to meta information about the request or response, body is the actual content of that response
92
Is a body required for a valid HTTP message?
no - not at a protocol level, it is always optional. when you work with APIs or designing APIs you want the body to be required sometimes, but this is at the app level, not the protocol level
93
What is NPM?
(Node Package Manager used to stand for, but expanded so much that it wasn't just for node packages) a library / registry where developers can share reusable code that help solve specific problems
94
What is a package?
a directory that contains a file or files of reuse-able code that is shared on npm
95
How can you create a package.json with npm?
npm init
96
What is a dependency and how to you add one to a package?
used to specify that our package is compatible with a specific version of an npm package dependency is another package of software that your package of sotftware depends on npm install package.json npm install express
97
What happens when you add a dependency to a package with npm?
creates a node_modules directory updates your package.json dependencies downloads that to the modules folder then goes into that package.json file and adds dependencies & adds whatever else is needed until everything has been unwrapped dependencies = list of things to download
98
How do you add express to your package dependencies?
by using npm to install the express package | npm install express
99
What Express application method starts the server and binds it to a network PORT?
app.listen( ) web traffic default port # normal: 80 secure (https): 443 default response to any request made on the express server: 404 Not Found, content of the page is cannot GET or cannot POST
100
How do you mount a middleware with an Express application?
app.use( )
101
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req & res
102
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
103
What is the significance of an HTTP request's method?
indicates the desired action to be performed for a given resource
104
What does the express.json( ) middleware do and when would you need it?
This method is used to parse the incoming requests with JSON payloads and is based upon the bodyparser. This method returns the middleware that only parses JSON and only looks at the requests where the content-type header matches the type option express middleware than parses raw json string body into an object and attaches it to the body of the request object - need it when you want to use the contents of an application/requestbody
105
What is PostgreSQL and what are some alternative relational databases?
Relational Database Management System that is free /open source and gets improvements each year (has been around for 30 years) Other popular relational databases include MySQL (also free), SQL Server by Microsoft, and Oracle by Oracle Corporation. Many relational database systems have an option of using the SQL (Structured Query Language) for querying and maintaining the database
106
What are some advantages of learning a relational database?
you are able to use SQL language with them If you are storing related data, then a relational database is probably a good first choice! (data related to each other like teachers, students, classes, classrooms). SQL is a gateway to all database languages they support good guarantees about data integrity. They can store and modify data in a way that makes data corruption as unlikely as possible. This means that developers can set up their database to reject "bad" data and not worry about data being "half written". ACID compliant transaction - if it tells you something successful, will tell you, but won't happen at all if doesn't work access data with single statement & declarative and you don't have to tell it HOW to get the data, just want to tell it what you want 3/4 of all databases used in a live web app use relational databases
107
What is one way to see if PostgreSQL is running?
sudo service postgresql status | or can check with top
108
What is a database schema?
A collection of tables is called a schema. A schema defines how the data in a relational database should be organized. In relational databases, you typically have to define your schema up front and the database server will make sure that any data being written to the database conforms to that schema.
109
What is a table?
container data stored in relations | A table is a list of rows each having the same set of attributes (columns)
110
What is a row?
rows contain data with the same sets of attributes that build tables (attributes = columns) ``` columns = fields that the record can have row = a record of data ```
111
What is SQL and how is it different from languages like JavaScript?
it is a declarative language which means programmers describe the results that they want to get out of it and the language in turn tries to fetch accordingly. JS is an imperative language where programmers tell it what to do and how to do it query execution strategy - IT figures out the steps that it takes
112
How do you retrieve specific columns from a database table?
using the select statement select "name", "price" (column names) from "products"; (table name) order of the results are not predictable if table name or column name is lowercase, don't need the quotes
113
How do you filter rows based on some specific criteria?
where "column name" = 'specific value' | can add conditionals & logical operators
114
What are the benefits of formatting your SQL?
Helps us to make the queries more readable and easy to understand When the queries are formatted and laid out with proper spacing it comes easy to find the errors in the query and fix the error
115
What are four comparison operators that can be used in a where clause?
= < > != =< =>
116
How do you limit the number of rows returned in a result set?
limit statement with integer | offset - used to skip rows
117
How do you retrieve all columns from a database table?
select statement with an *
118
How do you control the sort order of a result set?
order by statement + "columnName" or an expression or a comma separated list of columns can order by descending with desc at the end
119
How do you add a row to a SQL table?
insert into "table" ("list of columns") | values ('values')
120
What is a tuple?
ordered set of values in-between list and an object - each position in the tuple has a specific meaning. Each row is a tuple - values are jammed together & has a known size to recognize what is what every row is a tuple of the same size so that the engine knows where to go to grab each column
121
How do you add multiple rows to a SQL table at once?
insert into "table" ("column1, "column2") values (first one), (second one)
122
How do you get back the row being inserted into a table without a separate select statement?
returning statement with an *
123
How do you update rows in a database table?
update "table" set "column" = 'value' where ....
124
Why is it important to include a where clause in your update statements?
if it is not included, updates for all rows
125
How do you delete rows from a database table?
delete from "table" where ... can use and
126
How do you accidentally delete all rows from a table?
without using the where statement can also clear out tables - truncate clears data but keeps table definition drop removes table definition entirely - destroy database
127
What is a foreign key?
when tables share the same columns / values | connects two tables together - constraint on one table that says it can only contain a value from another table
128
How do you join two SQL tables?
using join statement select * from "first table" join "second table" using ("foreign key") Join "table2" ON "table1"."table1Id" = "table2"."table2Id"
129
How do you temporarily rename columns or tables in a SQL statement?
select "name". as "product"
130
What are some examples of aggregate functions?
``` max min avg count count distinct - counts only unique values sum ```
131
What is the purpose of a group by clause?
sometimes you want to ask questions about specific groups of data that share the same values across various attributes based on a column or calculated value i.e. find out the avg prices of all the products with the category "toys" and separately want to get an average price on all that are "electronics"
132
What are the three states a Promise can be in?
1. pending 2. fulfilled 3. rejected
133
How do you handle the fulfillment of a Promise?
using .then( ) method
134
How do you handle the rejection of a Promise?
.catch( ) method