JavaScript Flashcards

1
Q

What is the purpose of variables?

A

Variables are used to represent values/store information that can be used in your code.

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

How do you declare a variable?

A

by using the keyword var followed by a name to represent your variable.

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

By using the assignment operator followed by a value

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, dollar signs, or underscores. However, the name can NOT start with a number

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

variables names are sensitive to the capitalization of letters. Example: var keyword and var keyWord are two different variables.

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

a string is a data. type that is represented using characters and text.

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

a number is a data type represented by numbers and is used for calculating values. Used to store numeric values.

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

a boolean is a data type that only has two values: true and false. Good for logical reasoning

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

assignment operator. assigns values to avaraibles

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

by taking the variable name and assigning it a new value with he assignment operator, So long as this line of code comes after the initial value assignment.

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 is intentionally assigned an empty value and its type is an object, whereas undefined can be unintentional and means a variable has been declared but not assigned a value yet.

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

So you know what variable/information you are logging to 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

string, number, boolean, null, undefined

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

adding two strings together into one variable using + operator

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

addition or concatenation

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 a value to the variables original value.

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

What are objects used for?

A

objects are used for storing multiple values.

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

What are object properties?

A

object properties are variables that are stored within an object.

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

Describe object literal notation.

A

object literal notation involves a set of curly braces holding a comma separated list of properties and methods to which is being stored in a variable.

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

by using the delete operator(keyword) on the object

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.

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

What are arrays used for?

A

For storing lists of data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation.
brackets with data types separated by commas. All assigned into a variable.
26
How are arrays different from "plain" objects?
arrays have index numbers whereas objects have property names
27
What number represents the first index of an array?
0
28
What is the length property of an array?
the length property gives you the number of items in an array
29
How do you calculate the last index of an array?
array.length - 1
30
What is a function in JavaScript?
a javascript function is an object that can be called to perform a task.
31
Describe the parts of a function definition.
function keyword, optional name, a comma separated list of at least 0 parameters wrapped in ( ), and definition block.
32
Describe the parts of a function call.
function name followed by parenthesis containing any arguments.
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
the function definition includes the function keyword, function name, parameters, and definition block. the function call only has the function name and arguments.
34
What is the difference between a parameter and an argument?
parameters are for definitions whereas arguments are passed when the function is called.
35
Why are function parameters useful?
parameters are placeholders for data that will be collected when the function is called.
36
What two effects does a return statement have on the behavior of a function?
returns a value from the definition block and ends the function.
37
Why do we log things to the console?
to ensure our code is producing the right outputs. To check our work. Too visualize what the code is doing and identify mistakes if any.
38
What is a method?
A function that is being applied to an object
39
How is a method different from any other function?
Methods are associated with objects and have special access to information stored in its object
40
How do you remove the last element from an array?
pop method
41
How do you round a number down to the nearest integer?
floor method of the Math object
42
How do you generate a random number?
random method of the Math object
43
How do you delete an element from an array?
pop, shift, or splice method
44
How do you append an element to an array?
push method
45
How do you break a string up into an array?
split method
46
Do string methods change the original string? How would you check if you weren't sure?
No. log variables to the console to check.
47
Is the return value of a function or method useful in every situation?
no.
48
Give 6 examples of comparison operators.
less than, greater than, less than or equal to, greater than or equal to, not equal to, strictly equal to.
49
What data type do comparison expressions evaluate to?
booleans
50
What is the purpose of an if statement?
to check if a given condition is true or false, and if so, run code based on the condition.
51
Is else required in order to use an if statement?
no
52
Describe the syntax (structure) of an if statement.
if keyword, condition statement, code block
53
What are the three logical operators?
&&, ||, !
54
How do you compare two different expressions in the same condition?
by wrapping the expressions in parenthesis
55
What is the purpose of a loop?
to repeat a piece of code a number of times
56
What is the purpose of a condition expression in a loop?
A condition allows for a piece of code to run repeatedly until the condition evaluates as false, then the loop will stop.
57
What does "iteration" mean in the context of loops?
An iteration is a single execution of a code block in a loop.
58
When does the condition expression of a while loop get evaluated?
Before each execution of its code block.
59
When does the initialization expression of a for loop get evaluated?
The initialization gets evaluated once at the very beginning of the loop. Also comes before the condition.
60
When does the condition expression of a for loop get evaluated?
right before each loop iteration.
61
When does the final expression of a for loop get evaluated?
at the end of each loop iteration.
62
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break;
63
What does the ++ increment operator do?
increase by 1
64
How do you iterate through the keys of an object?
for...in loop
65
Why do we log things to the console?
For debugging and checking values.
66
What is a "model"?
It is a representation of something.
67
Which "document" is being referred to in the phrase Document Object Model?
The html document being displayed by the browser.
68
What is the word "object" referring to in the phrase Document Object Model?
Object refers to all the objects that make up the document.
69
What is a DOM Tree?
The DOM tree is the structure in which the browser creates a model of the document,
70
Give two examples of document methods that retrieve a single element from the DOM.
.querySelector() and .getElementById()
71
Give one example of a document method that retrieves multiple elements from the DOM at once.
.querySelectorAll()
72
Why might you want to assign the return value of a DOM query to a variable?
For reusability.
73
What console method allows you to inspect the properties of a DOM element object?
console.dir()
74
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
So the DOM has time to load before running any javascript.
75
What does document.querySelector() take as its argument and what does it return?
it takes a css selector in the form of a string and returns the FIRST element matching the selector.
76
What does document.querySelectorAll() take as its argument and what does it return?
it takes a css selector in the form of a string and returns ALL elements(node list) matching the selector.
77
What is the purpose of events and event handling?
Events and event handling allow for a web page to respond to a user interaction
78
What do [] square brackets mean in function and method syntax documentation?
They indicate that a parameter is optional
79
What method of element objects lets you set up a function to be called when a specific type of event occurs?
.addEventListener('event', functionName);
80
What is a callback function?
A call back function is a function that is passed into another function as an argument.
81
What object is passed into an event listener callback when the event fires?
The Event Object.
82
What is the event.target?
the target property of the event object is a reference to the element that the event was dispatched on.
83
What is the className property of element objects?
The className property is a property that allows you to access and set a value for the class name attribute of an element.
84
How do you update the CSS class attribute of an element using JavaScript?
With className property.
85
What is the textContent property of element objects?
textContent property is a property that represents an elements text content.
86
How do you update the text within an element using JavaScript?
By using .textContent property.
87
Is the event parameter of an event listener callback always useful?
no.
88
What event is fired when a user places their cursor in a form control?
focus event.
89
What event is fired when a user's cursor leaves a form control?
blur event
90
What event is fired as a user changes the value of a form control?
input event
91
What event is fired when a user clicks the "submit" button within a ?
submit event
92
What does the event.preventDefault() method do?
prevents the default function of an element.
93
What does submitting a form without event.preventDefault() do?
reloads the web page
94
What property of a form element object contains all of the form's controls.
elements property
95
What property of a form control object gets and sets its value?
value property
96
What is one risk of writing a lot of code without checking to see if it works along the way?
You risk making debugging very difficult
97
What is an advantage of having your console open when writing a JavaScript program?
check and debug your program in real time.
98
What is JSON?
JSON stands for JavaScript Object Notation and it is a text based data format that is very similar to object notation.
99
What are serialization and deserialization?
Serialization is the process of converting an object into a stream of bytes so it can be transferred over a network. deserialization is the process of converting a stream of bytes into an object.
100
Why are serialization and deserialization useful?
Sending information over a network.
101
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify();
102
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse();
103
How do you store data in localStorage?
call the setItem method of the localStorage object.
104
How to you retrieve data from localStorage?
call the getItem method of the localStorage object.
105
What data type can localStorage save in the browser?
key/value pairs in the form of strings.
106
When does the 'beforeunload' event fire on the window object?
just before the program closes, while the content is still visible.
107
Does the document.createElement() method insert a new element into the page?
No, it only creates an element, but does not insert it into the page. .
108
How do you add an element as a child to another element?
appendChild method
109
What do you pass as the arguments to the element.setAttribute() method?
you pass two string representing an attribute and its value
110
What steps do you need to take in order to insert a new element into the page?
create the element, give the element some content, and insert the element into the page.
111
What is the textContent property of an element object for?
The textContent property is used to get or set the text content of an element.
112
Name two ways to set the class attribute of a DOM element.
.className property or .setAttribute method
113
What are two advantages of defining a function to create something (like the work of creating a DOM tree)?
It can be reused to create new elements in different parts of the code.
114
What is the event.target?
The target method of the event object is a reference to the object that the event was fired on
115
Why is it possible to listen for events on one element that actually happen its descendent elements?
Event Bubbling.
116
What DOM element property tells you what type of element it is?
.tagName property.
117
What does the element.closest() method take as its argument and what does it return?
It takes a selector for its argument and return the first matching ancestor element.
118
How can you remove an element from the DOM?
.remove() method.
119
If you wanted to insert new clickable DOM elements into the page using JavaScript, how could you avoid adding an event listener to every new element individually?
adding an eventListener to an ancestor element.
120
What is the event.target?
The target property of the Event object is a reference to the object onto which the event was dispatched.
121
What is the affect of setting an element to display: none?
It hides and removes the element from the document flow.
122
What does the element.matches() method take as an argument and what does it return?
Its takes in a css selector in the form of a string and returns a boolean stating whether the object matches the selector.
123
How can you retrieve the value of an element's attribute?
GetAttribute method
124
What is a method?
A method is a function which is a property of an object
125
How can you tell the difference between a method definition and a method call?
a method call is attached to an object by a period whereas a method definition is stored inside an objects code block
126
Describe method definition syntax (structure).
property name, followed by function keyword with a set of parenthesis containing a comma separated list of parameters, followed by the definition block.
127
Describe method call syntax (structure).
object name, followed by method name with a set of parenthesis containing a comma separated list of arguments.
128
How is a method different from any other function?
a method is a function that is stored inside a property in an object and has special access to that objects data.
129
What is the defining characteristic of Object-Oriented Programming?
Its use of objects to store data and to have these objects interact with themselves and other objects. (pairs data with behavior)
130
What are the four "principles" of Object-Oriented Programming?
abstraction, encapsulation, inheritance, and polymorphism
131
What is "abstraction"?
being able to work with (possibly) complex things in simple ways.
132
What does API stand for?
Application Programming Interface
133
What is the purpose of an API?
An API give programmers a way to interact with a system in a simple way. They allow a programmers to request and receive data. They also allow different apps or services to interact with each other in various ways.
134
What is 'this' in JavaScript?
this refers the the object it was called on. It is an implicit parameter for all methods.
135
What does it mean to say that 'this' is an "implicit parameter"?
This is always there. It does not to be declared as a parameter.
136
When is the value of this determined in a function; call time or definition time?
call time.
137
How can you tell what the value of this will be for a particular function or method definition?
You can not know until it is being called.
138
How can you tell what the value of this is for a particular function or method call?
You can tell what this is by looking to the left of the dot on the method call. If there is no dot, this refers to the window object.
139
What kind of inheritance does the JavaScript programming language use?
prototype-based (or prototypal) inheritance.
140
What is a prototype in JavaScript?
a prototype is an object that contains reusable properties and methods that other objects can delegate tasks too.
141
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?
When these data types are created, they inherit these properties from the window through the __proto__ property. (Prototypes make it possible).
142
If an object does not have its own property or method by a given key, where does JavaScript look for it?
the proto-object.
143
What does the new operator do?
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. (Creates an object, attaches a proto property to that object, and returns this. )
144
What property of JavaScript functions can store shared behavior for instances created with new?
__proto__ property
145
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.
146
What is a "callback" function?
A callback function is a function that is being passed into another function as an argument.
147
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() method.
148
How can you set up a function to be called repeatedly without using a loop?
setInterval() method.
149
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
150
What do setTimeout() and setInterval() return
They return a timeoutID which is a positive integer that identifies the timer made by the setTimeout or setInterval method.
151
What is a client?
it is the service requester in the client-server model
152
What is a server?
it is the service/resource provider in the client-server model
153
Which HTTP method does a browser issue to a web server when you visit a URL?
get method
154
What three things are on the start-line of an HTTP request message?
An http method, a request target, and the HTTP version.
155
What three things are on the start-line of an HTTP response message?
The protocol version, a status code, and status text
156
What are HTTP headers?
HTTP headers are optional lines of text that specify the request or describe the body included in the message.
157
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN?
158
Is a body required for a valid HTTP request or response message?
No
159
What is AJAX?
Ajax is a technique for loading data into part of a page without it having to refresh the entire page
160
What does the AJAX acronym stand for?
Asynchronous Javascript And XML
161
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest()
162
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
load event
163
What is a code block? What are some examples of a code block?
Ac ode block is a set of code that is grouped together, usually by using {}. Funcitons, loops, and conditionals have code blocks.
164
What does block scope mean?
Block scope refers to the local scope of a given code block. Variables declared in a function are part of the function scope, but variables declared inside of a conditional that is stored inside of a function, only have access to its code block scope.
165
What is the scope of a variable declared with const or let?
block scope
166
What is the difference between let and const?
Let is mutable whereas const is immutable. Let can be reassigned a value whereas you cannot be reassign.
167
Why is it possible to .push() a new value into a const variable that points to an Array?
Arrays are mutable and its contents can be changed. Is is the variable that cannot be assigned an entirely new value
168
How should you decide on which type of declaration to use?
Never use variable. Favor const but generally use const for variables that will not change and let for variables that will be updated over time. But only use let if const is not possible.
169
What is the syntax for writing a template literal?
Wrapp string in backticks and use ${} to pass variables into the string.
170
What is 'string interpolation' ?
String interpolation is the process of evaluating a string that contains one or more placeholders(variables), which will be replaced by their appropriate values when the string is evaluated.
171
What is the syntax for defining an arrow function?
() => {}. Parenthesis are needed only when using 0 or more than one parameters. Curly braces can be left off and if so, no return keyword is needed.
172
When an arrow function's body is left without curly braces, what changes in its functionality?
No return keyword is needed
173
How is the value of this determined within an arrow function?
Regular functions: this is determined at call time. Arrow functions are determined at definition time.
174
What is Node js?
Node js is a runtime environment that allows you to run javascript outside of the browser.
175
What can Node.js be used for?
To run javascript outside of the browser for things such as building back ends for Web applications, command-line programs, or any kind of automation
176
What is a REPL?
REPL stands for read-evaluate-print-loop. This is an environment that takes single user inputs, executes them, and returns the result to the user. Just like Chrome DevTools Console
177
What is a JavaScript module?
A JavaScript module is a single JavaScript file
178
What values are passed into a Node.js module's local scope?
export, module, require(), __filename, __dirname
179
Give two examples of truly global variables in a Node.js program.
process and global.
180
What is the purpose of module.exports in a Node.js module?
The purpose of module.exports is to 'export' functionality from a node module so another module can access its functionality.
181
How do you import functionality into a Node.js module from another Node.js module?
By calling the require function and passing relative path as its argument.
182
What is a directory?
A directory is a file system that allows a user to group files together.
183
What is a relative file path?
a relative file path is a path to file from the current directory.
184
What is an absolute file path?
an absolute file path is path from a systems root directory.
185
What module does Node.js include for manipulating the file system?
fs
186
What is the JavaScript Event Loop?
The event loop is in charge of checking the call stack and if the call stock is available, it will place a queue task in the call stack.
187
What is different between "blocking" and "non-blocking" with respect to how code is executed?
blocking functions execute in a series whereas non-blocking functions execute concurrently.
188
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile
189
Are file operations using the fs module synchronous or asynchronous?
Both
190
What is NPM?
NPM is a package manager and the worlds largest software directory. Trick Question: NPM can refer to command line interface, website, or registry.
191
What is a package?
Packages are bits of reusable code that programmers can share so that other programmers can use those pieces of code in their own projects. A directory with one or more files but must include a package.json
192
How can you create a package.json with npm?
npm init -y
193
What happens when you add a dependency to a package with npm?
It will get added to the package.json and a node module directory will get added to the current directory.
194
How do you add express to your package dependencies?
npm install express
195
What Express application method starts the server and binds it to a network PORT?
.listen method
196
How do you mount a middleware with an Express application?
use method
197
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
The request and response objects
198
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json; charset=utf-8
199
What is Array.prototype.filter useful for?
To create a new array excluding certain elements
200
What is Array.prototype.map useful for?
For creating a new array of transformed elements
201
What is Array.prototype.reduce useful for?
For condensing all elements in an array to a single value
202
What is "syntactic sugar"?
syntax within a programming language that is designed to make things easier to read or to express
203
What is the typeof an ES6 class?
Function
204
Describe ES6 class syntax.
class keyword, class name, code block
205
What is "refactoring"?
The process of restructuring already existing code without changing its behavior.
206
How are ES Modules different from CommonJS modules?
ES module syntax is more compact,
207
What does express.static() return?
a middleware function.
208
What is the local __dirname variable in a Node.js module?
the __dirname variable give you an absolute path to the current working directory
209
What does the join() method of Node's path module do?
the join method of the Node's path module joins all given path segments together
210
What does fetch() return?
A promise that resolves to a response object
211
What is the default request method used by fetch()?
GET
212
How do you specify the request method (GET, POST, etc.) when calling fetch?
by passing an init object with a method property.