m-2-0522 Flashcards

(135 cards)

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

method definition is found inside the declaration of an object
method call is done by using name of the object followed by a period and the name of the method

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

Describe method definition syntax (structure).

A
var object = {
method: function () {
}
};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Describe method call syntax (structure).

A

object.method();

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

A method 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)

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 (possibly) complex things in simple ways

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 give programmers a way to interact with a system in a simplified, consistent fashion

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

What is this in JavaScript?

A

the value of this is determined by how a function is called

this describes the current context you’re 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

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

the value of this is 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

window 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!

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!

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

we can’t

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

prototype-based (or prototypal) inheritance

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

What is a prototype in JavaScript?

A

a JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects

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

A

prototype-based inheritance

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

prototype 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

The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

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

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.
26
What is a "callback" function?
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.
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()
28
How can you set up a function to be called repeatedly without using a loop?
setInterval()
29
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
30
What do setTimeout() and setInterval() return?
The returned timeoutID is a positive integer value which identifies the timer created by the call to setTimeout(). This value can be passed to clearTimeout() to cancel the timeout. The returned intervalID is a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.
31
What is a client?
a service requestor
32
What is a server?
provider of a resource or service
33
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
34
What three things are on the start-line of an HTTP request message?
HTTP method, request target, and HTTP version
35
What three things are on the start-line of an HTTP response message?
The protocol version, a status code, a status text
36
What are HTTP headers?
HTTP headers let the client and the server pass additional information with an HTTP request or response. An HTTP header consists of its case-insensitive name followed by a colon (:), then by its value. Whitespace before the value is ignored.
37
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN
38
Is a body required for a valid HTTP request or response message?
no
39
What is AJAX?
AJAX is a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest. Ajax allows you to update parts of the DOM of an HTML page without the need for a full page refresh. Ajax also lets you work asynchronously, meaning your code continues to run while the targeted part of your web page is trying to reload (compared to synchronously, which blocks your code from running until that part of your page is done reloading). With interactive websites and modern web standards, Ajax is gradually being replaced by functions within JavaScript frameworks and the official Fetch API Standard.
40
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
41
Which object is built into the browser for making HTTP requests in JavaScript?
To perform Ajax communication JavaScript uses a special object built into the browser—an XMLHttpRequest (XHR) object—to make HTTP requests to the server and receive data in response.
42
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
43
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
they have a shared prototype object
44
What is a code block? What are some examples of a code block?
a group of zero or more statements
45
What does block scope mean?
The current context of execution. The context in which values and expressions are "visible" or can be referenced.
46
What is the scope of a variable declared with const or let?
block scope
47
What is the difference between let and const?
let can be updated but not re-declared. | const cannot be updated or re-declared.
48
Why is it possible to .push() a new value into a const variable that points to an Array?
in this situation, the const variable is a reference to the array. the reference cannot be changed, but the values in the array can be.
49
How should you decide on which type of declaration to use?
scope reassignment redeclaration
50
What is the syntax for writing a template literal?
To create a template literal, instead of single quotes ( ' ) or double quotes ( " ) quotes we use the backtick ( ` ) character.
51
What is "string interpolation"?
the ability to substitute part of the string for the values of variables or expressions
52
What is destructuring, conceptually?
unpack values from arrays, or properties from objects, into distinct variables
53
What is the syntax for Object destructuring?
``` const user = { id: 42, isVerified: true }; ``` const {id, isVerified} = user; console. log(id); // 42 console. log(isVerified); // true
54
What is the syntax for Array destructuring?
const foo = ['one', 'two', 'three']; const [red, yellow, green] = foo; console. log(red); // "one" console. log(yellow); // "two" console. log(green); // "three"
55
How can you tell the difference between destructuring and creating Object/Array literals?
the object/array are on the left side or no side when creating the object/array are on the right side when destructuring
56
What is the syntax for defining an arrow function?
One param. With simple expression return is not needed: param => expression Multiple params require parentheses. With simple expression return is not needed: (param1, paramN) => expression ``` Multiline statements require body braces and return: param => { let a = 1; return a + param; } ``` ``` Multiple params require parentheses. Multiline statements require body braces and return: (param1, paramN) => { let a = 1; return a + param1 + paramN; } ```
57
When an arrow function's body is left without curly braces, what changes in its functionality?
expression vs statement
58
How is the value of this determined within an arrow function?
an arrow function captures the this value of the enclosing context instead of creating its own this context
59
What is a CLI?
command line interface
60
What is a GUI?
graphical user interface
61
``` 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 cat - cat command allows us to create single or multiple files, view content of a file, concatenate files and redirect output in terminal or files ls - It allows users to list files and directories from the Command Line Interface pwd - printing current working directory echo - echo is a command that outputs the strings that are passed to it as arguments touch - The touch command's primary function is to modify a timestamp. Commonly, the utility is used for file creation, although this is not its primary function. mkdir - allows users to create or make new directories mv - moves files or directories from one place to another rm - The rm command is used to delete files. cp - The cp command is a command-line utility for copying files and directories.
62
What are the three virtues of a great programmer?
laziness, impatience, hubris
63
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of a web browser.
64
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.
65
What is a REPL?
A read–eval–print loop (REPL), 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; a program written in a REPL environment is executed piecewise.
66
When was Node.js created?
May 27, 2009
67
What back end languages have you heard of?
Python, Java
68
What is the process object in a Node.js program?
The process object is a global that provides information about, and control over, the current Node.js process.
69
How do you access the process object in a Node.js program?
As a global, it is always available to Node.js applications without using require(). It can also be explicitly accessed using require(): const process = require('process');
70
What is the data type of process.argv in Node.js?
string type
71
What is a computer process?
In computing, 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. Depending on the operating system (OS), a process may be made up of multiple threads of execution that execute instructions concurrently.
72
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
134 processes
73
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. This will be extremely important when learning about applications made of multiple components, such as clients, servers, and databases.
74
What is a JavaScript module?
In JavaScript, a "module" is a single .js file.
75
What values are passed into a Node.js module's local scope?
The five parameters — exports, require, module, __filename, __dirname are available inside each module in Node. Though these parameters are global to the code within a module yet they are local to the module (because of the function wrapper as explained above). These parameters provide valuable information related to a module.
76
Give two examples of truly global variables in a Node.js program.
console and process
77
What is the purpose of module.exports in a Node.js module?
The main purpose of module. exports is to achieve modular programming. Modular programming refers to separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality.
78
How do you import functionality into a Node.js module from another Node.js module?
To include functions defined in another file in Node.js, we need to import the module. we will use the require keyword at the top of the file.
79
What is the JavaScript Event Loop?
The event loop is a constantly running process that monitors both the callback queue and the call stack.
80
What is different between "blocking" and "non-blocking" with respect to how code is executed?
Blocking methods execute synchronously and non-blocking methods execute asynchronously.
81
What is a directory?
In computing, a directory is a file system cataloging structure which contains references to other computer files, and possibly other directories.
82
What is a relative file path?
Relative Path is the hierarchical path that locates a file or folder on a file system starting from the current directory.
83
What is an absolute file path?
An absolute path always contains the root element and the complete directory list required to locate the file.
84
What module does Node.js include for manipulating the file system?
fs module
85
What method is available in the Node.js fs module for writing data to a file?
writeFile method
86
Are file operations using the fs module synchronous or asynchronous?
asynchronous
87
What is a client?
service requestor
88
What is a server?
provider of a resource or service
89
Which HTTP method does a browser issue to a web server when you visit a URL?
get
90
What is on the first line of an HTTP request message?
http method, request target, http version
91
What is on the first line of an HTTP response message?
protocol version, status code, status text
92
What are HTTP headers?
additional information passed by the client and/or server with an HTTP request or HTTP response
93
Is a body required for a valid HTTP message?
no
94
What is NPM?
node package manager | npm is the world's largest software registry
95
What is a package?
a directory with one or more files in it that also has a file called package.json with some metadata about the package
96
How can you create a package.json with npm?
npm init
97
What is a dependency and how to you add one to a package?
A dependency is a library that a project needs to function effectively npm install [ ...]
98
What happens when you add a dependency to a package with npm?
you can use that code with your code
99
How do you add express to your package dependencies?
$ npm install express
100
What Express application method starts the server and binds it to a network PORT?
the listen() method
101
How do you mount a middleware with an Express application?
calling the use method of the Express application object
102
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
the req object and the res object
103
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json; charset=utf-8
104
What is the significance of an HTTP request's method?
HTTP defines a set of request methods to indicate the desired action to be performed for a given resource. Specificity; (url is the resource) request method is what you're doing with that resource
105
What does the express.json() middleware do and when would you need it?
This is a built-in middleware function in Express. It parses incoming requests with JSON payloads and is based on body-parser. Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option. This parser accepts any Unicode encoding of the body and supports automatic inflation of gzip and deflate encodings. A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body), or an empty object ({}) if there was no body to parse, the Content-Type was not matched, or an error occurred.
106
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS). Other popular relational databases include MySQL (also free), SQL Server by Microsoft, and Oracle by Oracle Corporation.
107
What are some advantages of learning a relational database?
relational databases are good at storing related data and support good guarantees about data integrity
108
What is one way to see if PostgreSQL is running?
sudo service postgresql status
109
What is a database schema?
A collection of tables
110
What is a table?
A table is a list of rows each having the same set of attributes.
111
What is a row?
a record of data
112
What is SQL and how is it different from languages like JavaScript?
Structured Query Language is a programming language designed for managing (retrieving, creating, and manipulating) data held in a relational database management system. SQL is declarative. JavaScript is imperative.
113
How do you retrieve specific columns from a database table?
The query starts with the select keyword. The select keyword is followed by a comma-separated list of column names, each surrounded by " double quotes. The column names are followed by a from clause specifying which table to retrieve the data from. The query must end in a ; semicolon. SQL keywords such as select and from are not case-sensitive. SQL does not have to be indented, but you should do it anyway for consistent style and therefore readability.
114
How do you filter rows based on some specific criteria?
``` select "productId", "name", "price" from "products" where "category" = 'cleaning'; ```
115
What are the benefits of formatting your SQL?
SQL does not have to be indented, but you should do it anyway for consistent style and therefore readability.
116
What are four comparison operators that can be used in a where clause?
Other comparisons like <, >, and != are available too
117
How do you limit the number of rows returned in a result set?
``` select "name", "description" from "products" order by "price" desc limit 1; ```
118
How do you retrieve all columns from a database table?
select * | from "products";
119
How do you control the sort order of a result set?
select * from "products" order by "price";
120
How do you add a row to a SQL table?
insert into "products" ("name", "description", "price", "category") values ('Ostrich Pillow', 'Feel comfy and cozy!', 99, 'self care');
121
What is a tuple?
a list of values
122
How do you add multiple rows to a SQL table at once?
insert into "products" ("name", "description", "price", "category") values ('Ostrich Pillow', 'Feel comfy and cozy!', 99, 'self care'), ('Tater Mitts', 'Scrub some taters!', 6, 'cooking') returning *;
123
How do you get back the row being inserted into a table without a separate select statement?
returning clause
124
How do you update rows in a database table?
update "products" | set "price" = 100;
125
Why is it important to include a where clause in your update statements?
to only target specific rows
126
How do you delete rows from a database table?
delete from "products" where "productId" = 24 returning *;
127
How do you accidentally delete all rows from a table?
delete from "products";
128
What is a foreign key?
an attribute that links to another table
129
How do you join two SQL tables?
select * from "products" join "suppliers" using ("supplierId");
130
How do you temporarily rename columns or tables in a SQL statement?
select "products"."name" as "product", "suppliers"."name" as "supplier" from "products" join "suppliers" using ("supplierId");
131
What are some examples of aggregate functions?
max(), avg(), count(), min(), sum(), every() | takes a list of values and creates a single value
132
What is the purpose of a group by clause?
to separate rows into groups and perform aggregate functions on those groups of rows
133
What are the three states a Promise can be in?
pending fulfilled rejected
134
How do you handle the fulfillment of a Promise?
then method of the Promise object
135
How do you handle the rejection of a Promise?
catch method of the Promise object