Module 2 Flashcards
What is a method?
a function that is a property of an object
How can you tell the difference between a method definition and a method call?
the . call
Describe method definition syntax (structure).
__name of method__ : function(__parameters__) {
–code–
}
Describe method call syntax (structure).
__name of obj__ . __name of method__(__args__)
How is a method different from any other function?
it is a property of an object
What is the defining characteristic of Object-Oriented Programming?
objects can contain both data (as properties) and behavior (as methods); taking related data and functionality and putting them together in an object
What are the four “principles” of Object-Oriented Programming?
abstraction, encapsulation, inheritance, polymorphism
What is “abstraction”?
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)
What does API stand for?
application programming interface
What is the purpose of an API?
to connect computers/pieces of software to each other
What is this in JavaScript?
this is an implicit property of an object that refers to the object itself; when unassigned to an object this = Window object
What does it mean to say that this is an “implicit parameter”?
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
When is the value of this determined in a function; call time or definition time?
call time
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); } };"
character obj
How can you tell what the value of this will be for a particular function or method definition?
you cant; defined at call time
How can you tell what the value of this is for a particular function or method call?
find where the functionis called and look for the obj to the left of the dot
What kind of inheritance does the JavaScript programming language use?
prototype: objects inherit from other objects
What is a prototype in JavaScript?
an object that passes down properties
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?
prototypal inheritance from the global objs
If an object does not have it’s own property or method by a given key, where does JavaScript look for it?
its prototype
What does the new operator do?
creates an instance from a constructor function
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
What does the instanceof operator do?
checks the prototype tree of an object to see if something is there
What is a “callback” function?
a function that is used as an argument for another function
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()
How can you set up a function to be called repeatedly without using a loop?
setInterval( __function__ , __time (ms)_ )
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 ms
What do setTimeout() and setInterval() return?
numeric id for that timer
What is a client?
the client is the one that makes a request of a server (a person, cpu, app, etc)
What is a server?
provide data, service or function; receive requests –> send response
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What three things are on the start-line of an HTTP request message?
http method, request target, http version
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)
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)
Where would you go if you wanted to learn more about a specific HTTP Header?
https://httpie.io/docs#usage
Is a body required for a valid HTTP request or response message?
no
What is AJAX?
building webpages using XMLHttpRequest; allows you to update DOM w/out refreshing page
What does the AJAX acronym stand for?
asynchronous javascript and xml
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest()
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
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
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
What does block scope mean?
the code only applies to within a code block
What is the scope of a variable declared with const or let?
block
What is the difference between let and const?
let can be reassigned; const cannot
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
How should you decide on which type of declaration to use?
determine if you need to reassign the variable or not
What is the syntax for writing a template literal?
a string wrapped in ` `
What is “string interpolation”?
subbing values of vars into strs
What is destructuring, conceptually?
simply assigning a property’s value to a variable
What is the syntax for Object destructuring?
let {__property name1__ , __property name2__} = __object__
What is the syntax for Array destructuring?
let [__var 1__ , __var2__ ] = __array__
How can you tell the difference between destructuring and creating Object/Array literals?
the [ ] vs { }
What is the syntax for defining an arrow function?
const \_\_var\_\_ = ( \_\_para1\_\_, \_\_para2\_\_, ...) => { \_\_\_\_\_code\_\_\_\_\_ return \_\_\_\_\_\_ }
OR
const __var__ = ( __para1__, __para2__, …) => ___code__
When an arrow function’s body is left without curly braces, what changes in its functionality?
you do not need a return statement
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)
What is a CLI?
command-line interfaces
What is a GUI?
graphical user interface; visualizes CPU processes to make them understandable (ex: any CPU application)
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__
What are the three virtues of a great programmer?
laziness, impatience, hubris
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
What can Node.js be used for?
build the back end of web based apps, command-line programs, automation script
What is a REPL?
read-evaluate-print loop; it is an interface that executes code in a piece-wise fashion
When was Node.js created?
2009
What back end languages have you heard of?
none
What is the process object in a Node.js program?
global obj that provides info and control over the current node.js process
How do you access the process object in a Node.js program?
declare ‘process’
What is the data type of process.argv in Node.js?
object
What is a computer process?
an instance of a script
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
158
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
What is a JavaScript module?
a JS file
What values are passed into a Node.js module’s local scope?
(function(exports, require, module, \_\_filename, \_\_dirname) { // Module code actually lives in here });
Give two examples of truly global variables in a Node.js program.
export and module
What is the purpose of module.exports in a Node.js module?
to export functions to other modules
How do you import functionality into a Node.js module from another Node.js module?
with the require() function
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?…’
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)
What is a directory?
a collection of files/modules
What is a relative file path?
a file path that does not start at the root directory
What is an absolute file path?
a file path that starts at the root directory
What module does Node.js include for manipulating the file system?
fs
What method is available in the Node.js fs module for writing data to a file?
fs.Writefile
Are file operations using the fs module synchronous or asynchronous?
synchronous
What is a client?
a requestor of a service
What is a server?
the provider of a service or resource
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What is on the first line of an HTTP request message?
an HTTP method, a target and the lang of your request
What is on the first line of an HTTP response message?
^^
What are HTTP headers?
add extra information to the request (ie file formats, response format, etc)
Is a body required for a valid HTTP message?
no
What is NPM?
a way to create and share packages of reusable code that solve specific problems; dependency/package manager
What is a package?
a portion of JS code
How can you create a package.json with npm?
wit the ‘npm init –yes’ command
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)
What happens when you add a dependency to a package with npm?
it DLs with the package
How do you add express to your package dependencies?
‘npm install __pkgName__ –save’
What Express application method starts the server and binds it to a network PORT?
express.listen(__port#__, __callback function__)
How do you mount a middleware with an Express application?
the ‘use’ method
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req and res
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
JSON
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
What does the express.json() middleware do and when would you need it?
processes server requests before sending responses
What is PostgreSQL and what are some alternative relational databases?
open sourced RDMS (relational database management system); MySQL, Microsoft SQL Server, & Oracle
What are some advantages of learning a relational database?
learning how to use SQL
What is one way to see if PostgreSQL is running?
using the “top” command in the Command Line
What is a database schema?
a collection of tables in a database; defines columns, rules for data (type, potential values)
What is a table?
a list of rows w/ common attributes (columns)
What is a row?
an entity with attributes; an instance of the attributes in the columns
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)
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”;
How do you filter rows based on some specific criteria?
use ‘where’ keyword:
select “____“…
from “__name of table__”
where “name of col” = ‘value’;
What are the benefits of formatting your SQL?
readability
What are four comparison operators that can be used in a where clause?
, =, !=
How do you limit the number of rows returned in a result set?
use ‘limit’ keyword:
limit 10
How do you retrieve all columns from a database table?
use ‘ * ‘:
select *
How do you control the sort order of a result set?
‘order by’ keyword (+ asc or desc):
order by “col name” asc or desc
How do you add a row to a SQL table?
‘insert’ keyword:
insert into table name (“col1”, ….)
values (‘col val 1’, …)
What is a tuple?
an array for SQL
How do you add multiple rows to a SQL table at once?
use a comma separated list after ‘values’
How do you get back the row being inserted into a table without a separate select statement?
use ‘ returning * ‘
How do you update rows in a database table?
‘update’ keyword
Why is it important to include a where clause in your update statements?
it will update all vals of that column
How do you delete rows from a database table?
use ‘delete’ keyword:
delete from “table name”
where …
How do you accidentally delete all rows from a table?
delete from “table name”
What is a foreign key?
an identifier that references data stored in another table
How do you join two SQL tables?
after the ‘select’-‘from’ (before ‘where’) clauses:
join “table name” using (“common col name”)
How do you temporarily rename columns or tables in a SQL statement?
using aliasing: “actual name” as “alias”
What are some examples of aggregate functions?
avg() ; sum() ; max() ; min() ; count() ; every() ;
What is the purpose of a group by clause?
to take alike rows and collapse them to a single unit and run aggregate functions
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.
How do you handle the fulfillment of a Promise?
.then()
How do you handle the rejection of a Promise?
.catch()