JavaScript Flashcards

1
Q

What is the purpose of variables?

A

To store data into

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 variable name;

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

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

A

=

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, &, _

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 of the same name have to be typed with the same capitalization

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

Store or manipulate 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

Store or manipulate numbers

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

Data type showing binary states, true/false

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

Assigning a value to a variable

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

Reassign variable to a new value

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: non-existent or invalid object, null cannot be created unorganically, purposeful emptiness
Undefined: assigned to a variable with nothing

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?

A

More clear which variables are being logged and in what order

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, bigint, boolean, undefined, symbol, null

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

The joining of two or more strings to create on string

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

Adding one value to another

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

Add the value of the right operand to a variable and assigns the result to a variable

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

What are objects used for?

A

Groups a set of variables and functions

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

What are object properties?

A

Variables within a certain boundary in a storage location

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

Describe object literal notation

A

{ property: value, }

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

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, 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

Stores a list of values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation
[ variable1, variable 2, variable3]
26
How are arrays different from "plain" objects?
Instead of properties, arrays have index number for values
27
What number represents the first index of an array?
0
28
What is the length property of an array?
Total number of values
29
How do you calculate the last index of an array?
``` Create new variable (last index), assign to the result of length of array (number of students) minus 1. Create new variable (last student), assign to original array at the index of the new variable (last index). var lastIndex = numberOfStudents - 1; var lastStudent = students[lastIndex]; ```
30
What is a function in JavaScript?
Reusable block of code
31
Describe the parts of a function definition.
Name of a function, parameters code block
32
Describe the parts of a function call.
Name of the function, parentheses, argument
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function has keyword, code block and parameter | Call has a name and arguments
34
What is the difference between a parameter and an argument?
Parameter- placeholder | Argument- variable
35
Why are function parameters useful?
Act as a placeholder
36
What two effects does a return statement have on the behavior of a function?
1. Causes the function to produce a value we can use in our program. 2. Prevents any more code in the function's code block from being run.
37
Why do we log things to the console?
Debugging tool
38
What is a method?
Functions being called of an object
39
How is a method different from any other function?
Method is associated with an object
40
How do you remove the last element from an array?
Pop
41
How do you round a number down to the nearest integer?
Math.floor
42
How do you generate a random number?
Math.random
43
How do you delete an element from an array?
Splice
44
How do you append an element to an array?
Push
45
How do you break a string up into an array?
Split
46
Do string methods change the original string? How would you check if you weren't sure?
No, console.log
47
Is the return value of a function or method useful in every situation?
No
48
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
49
Give 6 examples of comparison operators.
greater than, less than, ==, ===, !=, !==, <=, >=
50
What data type do comparison expressions evaluate to?
Boolean
51
What is the purpose of an if statement?
Having your code make a decision
52
Is else required in order to use an if statement?
No
53
Describe the syntax (structure) of an if statement.
If (condition) { execute }
54
What are the three logical operators?
&&, | |, !
55
How do you compare two different expressions in the same condition?
Logical operators
56
What is the purpose of a loop?
To repeat a portion of code a set amount of times
57
What is the purpose of a condition expression in a loop?
An expression that is tested every time a code loops
58
What does "iteration" mean in the context of loops?
One repetition of a code block
59
When does the condition expression of a while loop get evaluated?
Before the code block runs
60
When does the initialization expression of a for loop get evaluated?
Before anything
61
When does the condition expression of a for loop get evaluated
Before each iteration
62
When does the final expression of a for loop get evaluated?
After each iteration
63
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break
64
What does the ++ increment operator do?
Increment by 1
65
How do you iterate through the keys of an object
Use a for-in loop
66
What are the four components of "the Cascade".
Source order, inheritance, specificity & !important
67
What does the term "source order" mean with respect to CSS?
The styling provided for an element last in your stylesheet is the styling that will ultimately take effect
68
How is it possible for the styles of an element to be applied to its children as well without an additional CSS rule
Inheritance
69
List the three selector types in order of increasing specificity.
Type, class, id
70
Why is using !important considered bad practice?
It makes debugging more difficult by breaking the natural cascading in stylesheets
71
Why do we log things to the console?
Debugging tool
72
What is a "model"?
A representation of something
73
Which "document" is being referred to in the phrase Document Object Model?
The whole html file
74
What is the word "object" referring to in the phrase Document Object Model?
The datatype object
75
What is a DOM Tree?
Element plus all of its children
76
Give two examples of document methods that retrieve a single element from the DOM.
queryselector, getelementbyname
77
Give one example of a document method that retrieves multiple elements from the DOM at once.
queryselectorall
78
Why might you want to assign the return value of a DOM query to a variable?
Ease of logging
79
What console method allows you to inspect the properties of a DOM element object?
console.dir
80
Why would a  tag need to be placed at the bottom of the HTML content instead of at the top?
Because the html isn’t rendered yet
81
What does document.querySelector() take as its argument and what does it return?
String, first element in the document with its name
82
What does document.querySelectorAll() take as its argument and what does it return?
Object, node list
83
What is the purpose of events and event handling?
To show the action resulting from a user, the code executed once the event takes place
84
Are all possible parameters required to use a JavaScript method or function?
No
85
What method of element objects lets you set up a function to be called when a specific type of event occurs?
addEventListener
86
What is a callback function
Function passed into another function as an argument
87
What object is passed into an event listener callback when the event fires?
Event
88
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
Where the event occurred in the DOM, console.log it, MDN
89
What is the className property of element objects?
Gets and sets the value of the class attribute of the element
90
How do you update the CSS class attribute of an element using JavaScript
Query select element and assign to class name property
91
What is the textContent property of element objects
The text content of its' elements
92
How do you update the text within an element using JavaScript?
Query select the element and assign to text content property
93
Is the event parameter of an event listener callback always useful?
No
94
Why is storing information about a program in variables better than only storing it in the DOM?
Variables can be used again anywhere in the JavaScript file
95
What event is fired when a user places their cursor in a form control?
Focus
96
What event is fired when a user's cursor leaves a form control?
Blur
97
What event is fired as a user changes the value of a form control
Input
98
What event is fired when a user clicks the "submit" button within a form?
Submit
99
What does the event.preventDefault() method do?
Prevents usual behavior of that object
100
What does submitting a form without event.preventDefault() do?
Refreshes the page
101
What property of a form element object contains all of the form's controls.
Element
102
What property of a form control object gets and sets its value?
Value
103
What is one risk of writing a lot of code without checking to see if it works so far?
Harder to debug
104
What is an advantage of having your console open when writing a JavaScript program?
Debugging
105
Does the document.createElement() method insert a new element into the page?
No
106
How do you add an element as a child to another element?
appendChild
107
What do you pass as the arguments to the element.setAttribute() method?
Name, value
108
What steps do you need to take in order to insert a new element into the page?
Create new element, setAttributes, appendChild
109
What is the textContent property of an element object for?
To change/insert text content of an element
110
Name two ways to set the class attribute of a DOM element.
setAttribute, className
111
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
reusing it, name recognition
112
What is the event.target?
The element to which the event is dispatched
113
Why is it possible to listen for events on one element that actually happen its descendent elements?
Event capturing
114
What DOM element property tells you what type of element it is
event.target.tagName
115
What does the element.closest() method take as its argument and what does it return?
Closest ancestor element
116
How can you remove an element from the DOM
Remove
117
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?
Add event listener to direct ancestor of element
118
What is the affect of setting an element to display: none
Hiding the element
119
What does the element.matches() method take as an argument and what does it return?
Takes in a selector string, returns a boolean
120
How can you retrieve the value of an element's attribute?
getAttribute
121
At what steps of the solution would it be helpful to log things to the console?
Checking variables in the loop
122
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?
Adding an event listener to every single object
123
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?
Separate conditional blocks for each view
124
What is JSON?
JavaScript Object Notation
125
What are serialization and deserialization?
Turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network Turning a stream of bytes into an object in memory
126
Why are serialization and deserialization useful?
Preserving the data | Using the data
127
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify
128
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse
129
How to you store data in localStorage?
localStorage.setItem
130
How to you retrieve data from localStorage?
localStorage.getItem
131
What data type can localStorage save in the browser?
String
132
When does the 'beforeunload' event fire on the window object?
Before the page unloads
133
What is a method?
A function which is a property of an object
134
How can you tell the difference between a method definition and a method call?
Method definition is the reusable code to be executed | Method call is when the code is executed
135
Describe method definition syntax (structure).
{
methodproperty: value},
136
Describe method call syntax (structure).
Object.method(argument);
137
How is a method different from any other function?
A method is called of an object
138
What is the defining characteristic of Object-Oriented Programming?
Having objects that can contain both data (as properties) and behavior (as methods)
139
What are the four "principles" of Object-Oriented Programming?
Abstraction, encapsulation, inheritance, polymorphism
140
What is "abstraction"?
Working with complex things in simple ways
141
What does API stand for?
Application programming interface
142
What is the purpose of an API?
Offer a service to other pieces of software
143
What is 'this' in JavaScript?
An implicit parameter
144
What does it mean to say that 'this' is an "implicit parameter"?
Available in function’s code block even though it was never included in function’s parameter list or never declared
145
When is the value of this determined in a function; call time or definition time
Call time
146
How can you tell what the value of 'this' will be for a particular function or method definition?
'this' is nothing
147
How can you tell what the value of 'this' is for a particular function or method call?
Object to the left of the dot, if no dot, it's window
148
What kind of inheritance does the JavaScript programming language use?
Prototype-based inheritance
149
What is a prototype in JavaScript?
An object that contains properties and methods that can be used by other objects.
150
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
They inherit it from a prototype object
151
If an object does not have its’ own property or method by a given key, where does JavaScript look for it?
In the prototypes
152
What does the new operator do?
Creates a blank object, adds a __proto__ property to the new object, gives ‘this’ variable a value, return ‘this’
153
What property of JavaScript functions can store shared behavior for instances created with new
Prototype
154
What does the instanceof operator do?
Checks if value on right is present in value on left
155
What is a "callback" function?
A function passed into another function as an argument
156
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
157
How can you set up a function to be called repeatedly without using a loop?
setInterval
158
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
0
159
What do setTimeout() and setInterval() return?
Positive integer value
160
What is a client?
Piece of computer software/hardware that accesses a service by available by a server
161
What is a server?
Piece of computer software/hardware that provides functionality for other programs or devices
162
Which HTTP method does a browser issue to a web server when you visit a URL?
Get
163
What three things are on the start-line of an HTTP request message?
HTTP method, request target/URL, HTTP version
164
What three things are on the start-line of an HTTP response message
Protocol version, status code, status text
165
What are HTTP headers?
Metadata of an http message
166
Where would you go if you wanted to learn more about a specific HTTP Header?
MDN
167
Is a body required for a valid HTTP request or response message?
No
168
What is AJAX?
Allows you to request data from a server and load it without having to refresh the entire page
169
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML
170
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
171
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server
Load
172
An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
They both share the same event.target.prototype
173
What is a code block? What are some examples of a code block?
A group of statements delimited by a pair of curly braces | 
Function code blocks
174
What does block scope mean?
When a variable is defined within a block, not accessible outside a block
175
What is the scope of a variable declared with const or let?
Block scope
176
What is the difference between let and const?
Let can be reassigned | Const cannot be reassigned
177
Why is it possible to .push() a new value into a const variable that points to an Array?
When you add to an array, you’re not reassigning the value of an array, you’re adding to the list of the array
178
How should you decide on which type of declaration to use?
If you want a value to be immutable, use const | If you want a value to be able to be reassigned, use let
179
What is the syntax for writing a template literal?
A string enclosed by back ticks
180
What is "string interpolation"?
The ability to substitute a part of the string for values of variables or expressions
181
What is destructuring, conceptually?
Breaking down an object, assigning the values of the object/array to variables
182
What is the syntax for Object destructuring?
let { property1: variable1, property2: variable2 } = object;
183
What is the syntax for Array destructuring
let [x, y, z] = array;
184
How can you tell the difference between destructuring and creating Object/Array literals
Destructuring has curly braces on left side of = | Creating has curly braces on right side of =
185
What is the syntax for defining an arrow function?
Const fnName = () => {} If there’s only one parameter, you don’t need parentheses Zero parameters, or two or more parameters, parentheses are mandatory
186
When an arrow function's body is left without curly braces, what changes in its functionality?
Automatically returned
187
How is the value of this determined within an arrow function?
Determined at definition time
188
What is a CLI?
Command line interfaces, commands to a computer program in the form of lines of text
189
What is a GUI?
Graphical user interface, form of user interface that allows users to interact with electronic devices through graphical icons and audio indicators instead of text-based user interfaces
190
Command 'man'
Interface to the online reference manuals
191
Command 'cat'
Concatenate files and print the output
192
Command 'ls'
List information about files
193
Command 'pwd'
Print name of current/working directory
194
Command 'echo'
Display line of text
195
Command 'touch'
Update the access and modification times of each file to current time
196
Command 'mkdir'
Create directories that don't already exist
197
Command 'mv'
Move or rename files
198
Command 'rm'
Remove files or directories
199
Command 'cp'
Copy files and directories
200
What are the three virtues of a great programmer?
Laziness, impatience, hubris
201
What is Node.js?
JavaScript runtime, executing JavaScript code not in a browser
202
What can Node.js be used for?
Used for back-end services and to build scalable network applications
203
What is a REPL?
Read-Eval-Print-Loop, program running a programming language awaiting additional inputs
204
When was Node.js created
2009
205
What back end languages have you heard of?
Python, php, ruby, java, c++, C#, rust, golang, perl, visual basic, elixir, haskell, rust, Clojure, kotlin, wasm
206
What is the process object in a Node.js program?
Global variable that provides information about, and control over, the current Node.js process
207
How do you access the process object in a Node.js program?
Open node.js or explicitly access using require(‘process’)
208
What is the data type of process.argv in Node.js?
Array
209
What is a JavaScript module?
Functionality organized in javascript files which can be reused throughout the node
210
What values are passed into a Node.js module's local scope?
module, exports, require, __filename, __dirname
211
Give two examples of truly global variables in a Node.js program.
Global, process, setTimeout, setInternal
212
What is the purpose of module.exports in a Node.js module?
To export code from a given file to another file that can access its’ code
213
How do you import functionality into a Node.js module from another Node.js module?
Require.(‘./relative-path’)
214
What is the JavaScript Event Loop?
Runtime model that executes code, collects and processes events, executes queued sub-tasks
215
What is different between "blocking" and "non-blocking" with respect to how code is executed
Blocking runs code in sequence, non-blocking runs parallel
216
What is a directory
A folder that has a collection of files
217
What is a relative file path?
Location of file or folder relative to the working directory
218
What is an absolute file path?
Complete location of file or folder relative to the root directory
219
What module does Node.js include for manipulating the file system?
fs module
220
What method is available in the Node.js fs module for writing data to a file?
writeFile()
221
Are file operations using the fs module synchronous or asynchronous?
Yes