Javascript Flashcards

(225 cards)

1
Q

What is the purpose of variables?

A

To store some sort of value

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

How do you declare a variable?

A

var varName = value;

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

How do you initialize (assign a value to) a variable?

A

varName = newValue;

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

What characters are allowed in variable names?

A

Letters, numbers, underscore, $dollar_sign

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

What does it mean to say that variable names are “case sensitive”?

A

“THIS” is different from “this” and “tHiS”

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

What is the purpose of a string?

A

To represent letters and characters

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

What is the purpose of a number?

A

To represent numerical data

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

What is the purpose of a boolean?

A

Used as a trigger for a condition

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

What does the = operator mean in JavaScript?

A

It’s the assignment operator

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

How do you update the value of a variable?

A

Assign a new value on the right side of the = operator

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

What is the difference between null and undefined?

A

null points to a nonexistent address

Undefined is a value for variables not yet defined

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

Why is it a good habit to include “labels” when you log values to the browser console?

A

It helps you recognize why you are logging onto the console

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

Give five examples of JavaScript primitives.

A

Number, string, boolean, array, object

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

What data type is returned by an arithmetic operation?

A

number

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

What is string concatenation?

A

Joining two or more strings together

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

What purpose(s) does the + plus operator serve in JavaScript?

A

String concatenation, addition for numbers

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

What data type is returned by comparing two values (, ===, etc)?

A

boolean

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

What does the += “plus-equals” operator do?

A

Adds the given value and re-assigns the new value to the variable on the left hand side of the operator

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

What are objects used for?

A

A data type that groups together a set of variables and functions to model real life ‘objects’

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

What are object properties?

A

Variables that hold data unique to that object

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

Describe object literal notation.

A
Declared with var objName = { };
Properties are stored between curly braces separated by commas
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How do you remove a property from an object?

A

delete obj.prop;

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

What are the two ways to get or update the value of a property?

A

Dot notation and bracket notation with assignment operator

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

What are arrays used for?

A

To store related data in an ordered list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
Declare with var arrName | Assign: [val1, val2, …];
26
How are arrays different from "plain" objects?
You access its elements using indices
27
What number represents the first index of an array?
0
28
What is the length property of an array?
It returns the length of an array or how many elements that array contains
29
How do you calculate the last index of an array?
arr.length - 1
30
What is a function in JavaScript?
To pack code for reuse throughout a program
31
Describe the parts of a function definition.
Function keyword, functionName(optional), parameters(optional), {code block}, return value(optional)
32
Describe the parts of a function call.
Function name and argument(s)
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function call doesn’t have the actual code, the function definition has the ‘function’ keyword
34
What is the difference between a parameter and an argument?
Parameters are defined in the function definition, arguments are passed in a function call
35
Why are function parameters useful?
They can be used to store data to be used (and sometimes modified) within a function
36
What two effects does a return statement have on the behavior of a function?
It exits a function immediately | It pushes a value out to where the function is called
37
Why do we log things to the console?
To keep track of the changes we make to our code and verifies our data. This prevents hard to find bugs because we’ll see it immediately with the log
38
What is a method?
Functions that are properties of an object
39
How is a method different from any other function?
Functions can only be called from an object through dot operator
40
How do you remove the last element from an array?
arr.pop();
41
How do you round a number down to the nearest integer?
Math.floor(num)
42
How do you generate a random number?
Math.random()
43
How do you delete an element from an array?
arr.splice(startIndex, deleteCount)
44
How do you append an element to an array?
arr.push(elem);
45
How do you break a string up into an array?
aString.split(‘delimiter’)
46
Do string methods change the original string? How would you check if you weren't sure?
Strings are immutable meaning they cannot be changed. Log to console if you aren’t sure
47
Roughly how many string methods are there according to the MDN Web docs?
About 35 not including ‘deprecated’ methods (not recommended to use because some browsers won’t support)
48
Is the return value of a function or method useful in every situation?
No, pop() will return a value, but you don’t need to use it
49
Roughly how many array methods are there according to the MDN Web docs?
About 40
50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
51
Give 6 examples of comparison operators.
>, >=.
52
What data type do comparison expressions evaluate to?
boolean
53
What is the purpose of an if statement?
To evaluate the boolean value of a conditional expression
54
Is else required in order to use an if statement?
No
55
Describe the syntax (structure) of an if statement.
If keyword, conditional statement between parentheses, code block to run if “if” statement is true
56
What are the three logical operators?
&& and, || or, ! logical not
57
How do you compare two different expressions in the same condition?
Use a logical operator between the two expressions
58
What is the purpose of a loop?
To run a block of code multiple times
59
What is the purpose of a condition expression in a loop?
To check if the loops should advance or not
60
What does "iteration" mean in the context of loops?
A single pass of the code block
61
When does the condition expression of a while loop get evaluated?
Before each iteration
62
When does the initialization expression of a for loop get evaluated?
Before the condition expression is checked for the first time Only gets initialized once
63
When does the condition expression of a for loop get evaluated?
After initialization and before the block of code runs | Subsequent loops, the condition expression is evaluated after the final (updating) expression
64
When does the final expression of a for loop get evaluated?
At the end of each iteration
65
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break
66
What does the ++ increment operator do?
Adds 1 to the variable and reassigns it back into the variable
67
How do you iterate through the keys of an object?
By using a for..in loop
68
What event is fired when a user places their cursor in a form control?
focus
69
What event is fired when a user's cursor leaves a form control?
blur
70
What event is fired as a user changes the value of a form control?
input
71
What event is fired when a user clicks the "submit" button within a ?
submit
72
What does the event.preventDefault() method do?
prevents the browser from automatically reloading the page with the form's values in the URL
73
What does submitting a form without event.preventDefault() do?
Reloads the page
74
What property of a form element object contains all of the form's controls.
Elements (?)
75
What property of a form control object gets and sets its value?
value
76
What is one risk of writing a lot of code without checking to see if it works so far?
You might miss a hard-to-find bug further down the line
77
What is an advantage of having your console open when writing a JavaScript program?
To check for bugs or mistakes while writing
78
What is the event.target?
It references the object in which the event was directed at
79
What is the effect of setting an element to display: none?
It hides the element from view on the screen
80
What does the element.matches() method take as an argument and what does it return?
It takes a selector (string) as an argument and it returns boolean value (true if it matches)
81
How can you retrieve the value of an element's attribute?
element.getAttribute(‘attributeName’) | Returns the value attached to the attribute
82
At what steps of the solution would it be helpful to log things to the console?
Pretty much each step logging to the console would be useful
83
If you were to add another tab and view to your HTML, but you didn't use event delegation, how would your JavaScript code be written instead?
You would have to query each new tab and view DOM element and add an event listener to each one
84
If you didn't use a loop to conditionally show or hide the views in the page, how would your JavaScript code be written instead?
You would have to write a stack of “if” and “else if” statements
85
What is JSON?
It stands for JavaScript Object Notation | It is a text-based data format which allows transmitting of data across networks
86
What are serialization and deserialization?
Serialization is converting a native object into a string for transmitting the data Deserialization is the opposite of that
87
Why are serialization and deserialization useful?
It allows the transmitting and translating of data that, for the most part, can’t be transmitted
88
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify(jsonObj)
89
How do you deserialize a JSON string into a data structure using JavaScript?
``` JSON.parse(jsonStr) const jsonStr = ‘{ “prop”:”value” }’; // quotes around prop required ```
90
How do you store data in localStorage?
window.localStorage.setItem( ‘prop-name’ , ‘jsonString’ )
91
How do you retrieve data from localStorage?
window.localStorage.getItem( ‘prop-name’ )
92
What data type can localStorage save in the browser?
JSON string
93
When does the 'beforeunload' event fire on the window object?
Before everything is unloaded
94
What is a method?
A function that is a property of an object
95
How can you tell the difference between a method definition and a method call?
A definition will have a block of code after the method’s name
96
Describe method definition syntax (structure).
objectName = { | methodName: function (para) { return something } };
97
Describe method call syntax (structure).
objectName.methodName(arguments);
98
How is a method different from any other function?
A method can only be called on the object it is associated with
99
What is the defining characteristic of Object-Oriented Programming?
The object
100
What are the four "principles" of Object-Oriented Programming?
Abstraction, encapsulation, inheritance, polymorphism
101
What is "abstraction"?
The process of taking a complex component of an object and making it more simplified to utilize its features
102
What does API stand for?
Application programming interface
103
What is the purpose of an API?
To allow users to utilize the abstraction of software & to share the functionality of a program
104
What is this in JavaScript?
An implicit parameter of all JS functions or the object itself or the global window object when not attached explicitly to an object
105
What does it mean to say that this is an "implicit parameter"?
It’s available in a function’s code block even when it’s not explicitly stated
106
When is the value of this determined in a function; call time or definition time?
Call time
107
``` 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); } }; ```
The character object
108
Given the above character object, what is the result of the following code snippet? Why? character.greet();
It’s-a-me, Mario! | this.firstName refers to the character object when calling the greet method
109
``` Given the above character object, what is the result of the following code snippet? Why? var hello = character.greet; hello(); ```
‘It’s-a-me, undefined!’
110
How can you tell what the value of this will be for a particular function or method definition?
The value of ‘this’ will be determined at function/method call depending if it has something to the left of the dot operator
111
How can you tell what the value of this is for a particular function or method call?
It will reference the object that is on the left of the dot operator. If there isn’t one, it will reference the global window object.
112
What kind of inheritance does the JavaScript programming language use?
prototypal
113
What is a prototype in JavaScript?
An object that contains properties that other objects can use
114
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?
These methods are defined on a prototype object and then set to be used by strings, arrays, and numbers
115
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
JS looks to see if it has a prototype property set in the prototype chain
116
What does the new operator do?
It creates an instance of a user-defined object Adds a property to the object (__proto__) ‘This’ now refer to the object created Returns ‘this’ if function doesn’t return an object
117
What property of JavaScript functions can store shared behavior for instances created with new?
The prototype property
118
What does the instanceof operator do?
Returns a boolean if “var” is an instance created by a constructor of an object
119
What is a "callback" function?
A function passed into another function as an argument
120
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(cbFn, delay);
121
How can you set up a function to be called repeatedly without using a loop?
setInterval(cbFn, delay);
122
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0 or immediately
123
What do setTimeout() and setInterval() return?
A timeout ID to store the timer’s ID. It can be used as an argument for clearTimeout()/clearInterval()
124
What is a client?
A computer or program that sends requests to access services available from servers
125
What is a server?
Hardware or software that provides functionality for other programs or devices after a request
126
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
127
What three things are on the start-line of an HTTP request message?
HTTP method, request target, HTTP version
128
What three things are on the start-line of an HTTP response message?
``` Protocol version (usually HTTP/1.1) Status code (200, 404, 302, etc) Status text (OK, NOT FOUND, etc) ```
129
What are HTTP headers?
Text appearing on top of request or response messages showing information about the HTTP message
130
Where would you go if you wanted to learn more about a specific HTTP Header?
mdn/HTTP/messages
131
Is a body required for a valid HTTP request or response message?
No, responses with a status code that sufficiently answers the request without the need for corresponding payload (like 201 Created or 204 No Content) usually don't.
132
What is AJAX?
A technique for loading data into a part of a page without having to refresh the entire page
133
What does the AJAX acronym stand for?
Asynchronous JavaScript and XML
134
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
135
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load
136
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
The each share the prototype method (hidden 4 levels into the prototype chain)
137
What is a code block? What are some examples of a code block?
A section of code contained between {curly braces} | ex/ the code that is run after after a for loop statement
138
What does block scope mean?
It means that the variable that is declared is only visible within the code block
139
What is the scope of a variable declared with const or let?
Block scope
140
What is the difference between let and const?
Variables declared with let are mutable, const variables are not
141
Why is it possible to .push() a new value into a const variable that points to an Array?
Because the value stored in an array variable is the address in which it is pointing to therefore the elements
142
How should you decide on which type of declaration to use?
Let & const if you want the variable to be block scope. Const if you want the variable to be constant/immutable
143
What is destructuring, conceptually?
It is a way to fetch elements stored inside of an array or object
144
What is the syntax for Object destructuring?
The object variable on right side of assignment operator (=) const, then the variables to store that data on left side inside curly braces If variables do not share the same property names, you need to put the variable names on right side of property name separated by a colon
145
What is the syntax for Array destructuring?
The array variable on right side of assignment operator (=) | const, then the variables to store the array elements on left side inside square brackets
146
How can you tell the difference between destructuring and creating Object/Array literals?
When destructuring, the object/array is on the right side of the assignment operator (=)
147
What is the syntax for writing a template literal?
Template literals are surrounded by backticks and an interpolated expressions begin with $ and curly braces around the expression
148
What is "string interpolation"?
It is a way to represent strings that are inserted into an expression not defined as a string
149
What is the syntax for defining an arrow function?
(param1, param2) => { code block } If there is only 1 parameter, parentheses are not needed If code block doesn’t have a statement, curly braces are not needed
150
When an arrow function's body is left without curly braces, what changes in its functionality?
It implicitly returns the statement inside of the code block
151
How is the value of this determined within an arrow function?
It doesn’t define its own ‘this’ value but rather it captures the ‘this’ value from the enclosing context
152
What is a CLI?
Command Line Interface
153
What is a GUI?
Graphical User Interface
154
What are the three virtues of a great programmer?
Laziness, impatience, hubris
155
What is Node.js?
A JavaScript runtime environment
156
What can Node.js be used for?
It can be used to execute JS code outside of a browser
157
What is a REPL?
read–eval–print loop A interactive computer programming environment that allows a single user to input code, execute it and the REPL returns the result
158
When was Node.js created?
May 27, 2009
159
What back end languages have you heard of?
Express, Django, Flask, Ruby on Rails, PHP, python, perl
160
What is a computer process?
An instance of a computer program running
161
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
I currently have about 200 process running according to my Task Manager
162
Why should a full stack Web developer know that computer processes exist?
A full-stack app or program requires multiple processes to work together so understanding processes lets the developer recognize how each piece can perform cohesively and to properly allocated resources to help load balance the server
163
What is the process object in a Node.js program?
It is a global object that provides information and control over the current Node.js process
164
How do you access the process object in a Node.js program?
You can handle the process object using its properties
165
What is the data type of process.argv in Node.js?
Array of strings
166
What is a JavaScript module?
A single JS file
167
What values are passed into a Node.js module's local scope?
Exports, require, module, __filename, __dirname
168
Give two examples of truly global variables in a Node.js program.
Console, process
169
What is the purpose of module.exports in a Node.js module?
To export the module into another file. Typically into a file that will use that module
170
How do you import functionality into a Node.js module from another Node.js module?
Const variable = require(‘./fileName) | fileName can be written with .js at end, but it is implied
171
What is the JavaScript Event Loop?
It is the queue in which messages are ran
172
What is the difference between "blocking" and "non-blocking" with respect to how code is executed?
Code is blocking if the event loops is being stopped because of that code
173
What is a directory?
A folder containing files
174
What is a relative file path?
It refers to the location in which a file is found relative to the current directory
175
What is an absolute file path?
It refers to the location that contains the root directory
176
What module does Node.js include for manipulating the file system?
fs (file system)
177
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile()
178
Are file operations using the fs module synchronous or asynchronous?
asynchronous
179
What is a client?
A computer or program that sends requests to access services available from servers
180
What is a server?
Hardware or software that provides functionality for other programs or devices after a request
181
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
182
What is on the first line of an HTTP request message?
HTTP method, request target, HTTP version
183
What is on the first line of an HTTP response message?
``` Protocol version (usually HTTP/1.1) Status code (200, 404, 302, etc) Status text (OK, NOT FOUND, etc) ```
184
What are HTTP headers?
Text appearing on top of request or response messages showing information about the HTTP message
185
Is a body required for a valid HTTP message?
No, responses with a status code that sufficiently answers the request without the need for corresponding payload (like 201 Created or 204 No Content) usually don't.
186
What is NPM?
Stands for nose-picking-monkeys | It is a package managing tool by node that allows users to download and install packages to use
187
What is a package?
A library of code created by people that are available to be used from npm
188
How can you create a package.json with npm?
npm init --yes
189
What is a dependency and how do you add one to a package?
A third-party piece of software used to solve a single problem npm install nameOfPackage
190
What happens when you add a dependency to a package with npm?
It gets added to the list of “dependencies” in package.json and A directory holding the dependency is added to ‘node_modules’
191
How do you add express to your package dependencies?
Initialize package.json, install express
192
What Express application method starts the server and binds it to a network PORT?
listen()
193
How do you mount a middleware with an Express application?
With app.use() method
194
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
Request object & response object
195
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
196
What is the significance of an HTTP request's method?
To clearly indicate the desired action to be performed But there is little to no significance since the method written is only there for semantics because the code block can be written in any way
197
What does the express.json() middleware do and when would you need it?
It parses incoming requests that are structured as JSON objects.
198
What is PostgreSQL and what are some alternative relational databases?
A relational database management system | MySQL, SQL Server, Oracle
199
What are some advantages of learning a relational database?
Guarantees data integrity, widely used, portable skill to have
200
What is one way to see if PostgreSQL is running?
‘sudo service postgresql status’ or ‘top’
201
What is a database schema?
A collection of tables | Sometimes refer to blueprints for building a table
202
What is a table?
A set of data elements organized in columns and rows
203
What is a row?
A data entry that shows the values for each attribute
204
What is SQL and how is it different from languages like JavaScript?
It’s a language used to interact with relational databases.
205
How do you retrieve specific columns from a database table?
Select “specific column” from “table”
206
How do you filter rows based on some specific criteria?
Where (condition) | Like “age” > 10
207
What are the benefits of formatting your SQL?
Readability and consistency
208
What are four comparison operators that can be used in a where clause?
=, , !=
209
How do you limit the number of rows returned in a result set?
At the end of your query, you add “limit x” x is the number of rows to limit
210
How do you retrieve all columns from a database table?
Select * from “table”
211
How do you control the sort order of a result set?
After: from “table” ⇒ order by “column” | desc for descending order
212
How do you add a row to a SQL table?
``` Use insert into keywords “tableName” Values keyword (“value1”, “value2”) ```
213
What is a tuple?
A finite ordered list of values
214
How do you add multiple rows to a SQL table at once?
After the values keyword, each tuple is separated by a comma
215
How do you get back the row being inserted into a table without a separate select statement?
After the values, use the returning clause
216
How do you delete rows from a database table?
‘delete by’ keywords
217
How do you accidentally delete all rows from a table?
By omitting the where clause that includes a conditional
218
What is a foreign key?
A relational attribute that can be used to join 2 or more tables together
219
How do you join two SQL tables?
JOIN “table” USING (“attribute”)
220
How do you temporarily rename columns or tables in a SQL statement?
Using an alias with the ‘AS’ keyword
221
What are some examples of aggregate functions?
Max, avg, count, sum
222
What is the purpose of a group by clause?
To groups a collection of rows to perform aggregate functions on those rows
223
What are the three states a Promise can be in?
Pending, fulfilled, rejected
224
How do you handle the fulfillment of a Promise?
Call the then() method
225
How do you handle the rejection of a Promise?
Call the catch() method