Javascript Flashcards

1
Q

What is the purpose of variables?

A

To hold values

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 (name of var)

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

var (name of var) = 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

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

The casing matters when trying to use 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

To hold a collection of 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 hold 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

To announce if a value is true or false. Likewise, it can announce 0 for false and 1 for true

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

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

re assign the value using the the name of the variable and = to 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 is an object, but undefined is a type

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

To identify what is being printed to the console.

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

Give 5 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

2 strings combine and become 1 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

Increment by 1

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?

A

boolean

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

What does the += operator do?

A

Combines the left with the right

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

What are objects used for?

A

A collection of data

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

What are object properties?

A

data fields of an object

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

Describe object literal notation.

A

When you declare the object’s properties literally

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

Collection of data

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Describe array literal notation
create an array and place items within the indexes of the array
26
How are arrays different from "plain" objects?
objects do not require uniqueness
27
What number represents the first index of an array?
0
28
What is the length property of an array?
Tells how many elements are in an array
29
How do you calculate the last index of an array?
length -1
30
What is a function in JavaScript?
A set of statements that performs a task
31
Describe the parts of a function definition
function keyword, "name", parameters within parenthesis, curly braces
32
Describe parts of a function call
function name, arguements
33
WHen comparing them side-by-side, what are the differences between a function call and function definition
the call only requires the name of the function and the possible arguments, the definition requires the keyword and the steps.
34
What is the difference between a parameter and an argument
parameter is what the function requires, but an argument is what the user passes to be used in the function
35
what two effects does a return statement have on the behavior of a function?
Exits the function and returns the value to the original call.
36
Why do we log things to the console?
To debug and check data
37
What is a method?
A function within a class
38
How is a method different from any other function?
It must be called using an object
39
How do you remove the last element of an array?
pop()
40
How do you round a number down to the nearest integer?
floor
41
How do you generate a random number?
random
42
How do you delete an element from an array?
splice
43
How do you append an element to an array?
push
44
How do you break a string up into an array?
split
45
Do string methods change the original string? How would you check if you weren't sure?
No they replace it. You would log the string
46
Roughly how many string methods are there according to the MDN web docs?
25
47
Is the return value of a function or method useful in every situation?
No
48
Roughly how many array methods are there according to the MDN web docs?
30
49
What three-letter acronym should you always include in your google search about a javascript method or css property?
MDN
50
Give 6 examples of comparison operators
>, =, !==
51
What data type do comparison expressions evaluate to?
boolean
52
What is the purpose of an if statement?
To evaluate different conditions
53
Is else required in order to use an if statement?
No
54
Describe the syntax(structure) of an if statement.
keyword if, condition, block
55
What are the three logical operators?
AND, OR, NOT
56
How do you compare two different expressions in the same condition?
&& or ||
57
What is the purpose of a loop?
To repeat lines of codes
58
What is the purpose of a condition expression in a loop?
To let it know when to exit the loop
59
What does iteration mean in the context of loops?
Incrementing a counter. So each repeated step
60
When does the condition expression of a while loop get evaluated?
At the beginning
61
When does the initialization of a for loop get evaluated?
At the beginning
62
When does the condition expression of a for loop get evaluated?
after the initialization and after increment
63
When does the final expression of a for loop get evaluated?
At the end of the code block
64
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break;
65
what does ++ increment operator do?
Increments the variable in use, but depending on if its in the front or back it will be used first then incremented or incremented then used
66
How do you iterate through the keys of an object?
for in
67
Why do we log things to the console?
Debugging and to find the results of data
68
What is a model?
The outline of an object
69
Which document is being referred to in the phrase Document Object Model
The HTML
70
What is the word object referring to in the phrase DOM
The elements in the html
71
What is a DOM tree?
tags
72
Give two examples of document methods that retrieve a single element from the dom.
querySelector, getElementByID
73
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll
74
Why might you want to assign the return value of a DOM query to a variable?
To retain that information
75
What console method allows you to inspect the properties of a DOM element object?
console.dir()
76
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
The element would not be created at the time the script is ran. So it would not affect the HTML
77
What does querySelector() take as its argument and what does it return?
Object, element
78
What does document.QuerySelectorAll() take as its argument and what does it return?
object, nodeList
79
Why do we log things to the console?
To read about the object and debug
80
What is the purpose of the events and event handling?
Event is what occurs when the user interacts with the page and event handling is processing what to do when that event occurs
81
What do the [] square brackets mean in function and method syntax documentation?
optional arguments
82
What method of element objects lets you set up a function to be called when a specific type of event occurs?
eventlistener
83
What is a callback function?
function that is meant to be passed as part of another function's argument
84
What object is passed into an event listener callback when the event fires?
event
85
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
element being targeted. html, console
86
What is the difference between adding () to callback functions in addEventListener?
When you use () the function is called, but it is not waiting for an event to fire. We pass the name in the function rather than the function itself. Trigger when the click happens, not when the event is made
87
What is the className property of element objects?
Allows you to change the class attribute of an element
88
How do you update the CSS class attribute of an element using JavaScript?
className
89
What is the textContent property of element objects?
Allows you to change the textContent attribute
90
How do you update the text within an element using JavaScript?
Update the textContent property.
91
Is the event parameter of an event listener callback always useful?
no
92
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
no
93
Why is storing information about a program in variables better than only storing it in the DOM?
tracking, don't want to store in the DOM
94
What event is fired when a user places their cursor in a form control?
focus
95
What even is fired when a user's cursor leaves a form control?
blur
96
What event is fired as a user changes the value of a form control?
input
97
What event is fired when a user clicks the submit button within a form?
the data in the form is passed
98
What does the event.preventDefault() method do?
Cancels an event
99
What does submitting a form without event.preventDefault() do?
Submits the form and resets
100
What property of a form element object contains all of the form's controls?
elements
101
What property of form control object gets and sets its value
value
102
What is one risk of writing a lot of code without checking to see if it works so far?
debugging will be a pain
103
What is an advantage of having your console open when writing a JS program/
Can see errors as you got and it tells you what lines.
104
Does the document.createElement() method insert a new element into the page?
no
105
How do you add an element as a child to another element?
appendChild
106
What do you pass as the arguments to the element.setAttribute() method?
attribute name, value
107
What steps do you need to take in order to insert a new element into the page?
append it to an element that is on the html
108
What is the textContent property of an element object for?
text content, text the user can see
109
Name 2 ways to set the class attribute of a DOM element.
setAttribute, classList, className
110
What are two advantages of defining a function to do create something?
Can repeatedly create an object without having to explicitly write it. So if you have a list of data, then you can just write a for loop
111
The transition property is shorthand for which 4 CSS properties?
delay, duration, property, timing-function
112
What is the event.target?
The element that the event was triggered on
113
Why is it possible to listen for events on one element that actually happen its descendent elements?
Event delegation
114
What DOM element property tells you what type of element it is?
target.tagName
115
What does the element.closest() method take as its argument and what does it return?
string (DOMString) and it returns an element obj which is the closest ancestor of the selected element
116
How can you remove an element from the DOM?
element.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?
put it in a div
118
what is the event-target?
element that the event was triggered on?
119
What is the affect of setting an element to display: none?
Removes the display
120
What does the element.matches() method take as an argument and what does it return?
selector, returns a boolean
121
How can you retrieve the value of an element's attribute?
getAttribute()
122
At what steps of the solution would it be helpful to log things to the console?
All
123
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?
multiple event listeners
124
If you didn't use a loop to conditionally show or hide the views in the page, how would your javascript code b written instead?
many many lines
125
What is JSON?
Javascript object notation
126
What are serialization and deserialization?
Serialization - Converting objects into byte stream Deserialization - Turning byte stream into objects
127
Why are serialization and deserialization useful?
Allows us to send data
128
How do you serialize a data structure into a JSON string using JavaScript?
.stringify()
129
How do you deserialize a JSON string into a data structure using javascript?
.parse()
130
How do you store data in localstorage?
localstorage.setItem()
131
How do you retrieve data from localstorage?
getItem()
132
What data type can localStorage save in the browser?
string
133
When does the beforeUnload event first on the window object?
right before closing the window
134
What is a method?
a function which is a property of an object
135
How can you tell the difference between a method definition and a method call?
A method definition goes within the object and takes parameters. Method call will call the object and send arguments
136
Describe method definition syntax(structure).
function name, parameters, definition;
137
Describe method call syntax(structure).
obj, method name, arguements;
138
How is method different from any other function?
Methods belong to objects so they can manipulate the object and its properties
139
What is the defining characteristic of OOP?
The use of objects to hold properties
140
What are the four principles of OOP?
Abstraction, encapsulation, inheritance, polymorphism
141
What is abstraction?
Hiding functionality from users. ie interfaces
142
What does API stand for?
Application Programmign Interface
143
What is the purpose of an API
Defines interactions between multiple software intermediaries
144
What is this in JavaScript?
refer to the object that it currently is referring to
145
What does it mean to say that this is an implicit parameter?
does not need to be specified
146
When is the value of this determined in a function; call time or definition time?
call time
147
How can you tell what the value of this will be for a particular function or method definition?
The object from where its being referred
148
How can you tell what the value of this is for a particular function or method call?
The object that calls the function
149
What kind of inheritance does the javascript language use?
Prototypal inheritance
150
What is a prototype in javascript?
template object
151
How is it possible to call methods on strings, arrays, and numbers even though those methods dont actually exist on objects, arrays, and numbers?
proto
152
If an object does not have its own property or method by a given key, where does javascript look for it?
proto
153
What does the new operator do?
Creates a new instance of an object
154
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
155
What does the instanceof operator do?
Check if the object is inheriting from the specified object
156
What is a callback function?
A function passed into another function as an argument
157
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()
158
How can you set up a function to be called repeatedly without using a loop?
interval
159
What is the default time delay if you omit the delay parameter from setTimeOut or setInterval()?
0
160
What do setTimeout() and setInterval() return?
timeoutID
161
What is a coded block? What are some examples of a code block?
Its code that is grouped together that can be executed within its scope. functions, for statements, if statements
162
What does block scope mean?
Variables that are declared within a block only exist within that block
163
What is the scope of a variable declared with const or let?
The block
164
Why is it possible to .push() a new value into a const variable that points to an array?
const are not immutable. The variable itself is read only, but you may manipulate the contents inside. You just cannot instantiate the variable
165
How should you decide on which type of declaration to use?
const for all things | let if you can't const.
166
What is destructuring, conceptually?
Decompose the properties of an object or the indexes of an array to separate them to create specific variables
167
What is the syntax for object destructuring?
let {object: name} = "object to get from"
168
What is the syntax for Array destructuring?
let {object} = "array to get from"
169
How can you tell the difference between destructuring and creating Object/Array literals?
If the declaration of the variable is on the left or right side.
170
What is the syntax for writing a template literal?
` ${variable}`
171
What is "string interpolation"?
Replace placeholders with values in a string literal
172
What is the syntax for defining an arrow function?
() => {}
173
When an arrow function's body is left without curly braces, what changes in its functionality?
its a 1 liner
174
How is the value of this determined within an arrow function?
it is determined by the surrounding scope
175
What is a CLI?
Command line interface
176
What is a GUI?
Graphical User Interface
177
man
man cat
178
cat
cat txt file
179
ls
ls any directory
180
pwd
pwd to find your directory
181
echo
to write arguments
182
touch
Create a file
183
mkdir
Create directory
184
mv
Move
185
rm
Remove
186
cp
copy
187
What are the three virtues of a great programmer?
lazy, patience, huburous
188
What is Node.js?
Server environment
189
What can Node.js be used for?
Single-threaded, non-blocking, asynchronously programming, generate dynamic page content, crud on server, collect form data, add, delete, modify data in db
190
What is REPL?
Read-Eval-Print-Loop, | Shell that processes node expressions
191
When was Node.js created?
2009
192
What back end languages have you heard of?
java, .net, python, ruby, php, go
193
What is a process?
Computer program that is being executed on 1 or more threads
194
Roughly how many computer processes are running on your host operating system?
151
195
Why should a full stack web developer know that computer processes exist?
Application speed, memory needed, optimization, bottlenecks
196
What is the process object in a Node.js program?
Global object that provides information about the current Node.js process
197
How do you access the process object in a Node.js program?
process object and node command
198
What is the data type of process.argv in Node.js?
Array
199
What is a javascript module?
Exports specific objects making them available
200
What values are passed into a node.js module's local scope?
exports, require, module, __filename, __dirname
201
Give two examples of truly global variables in a Node.js program
global process
202
What is Array.prototype.filter useful for?
You can filter out unwanted or wanted data.
203
What is Array.prototype.map useful for?
When you want to manipulate values within an array
204
What is Array.prototype.reduce useful for?
To reduce to 1 obj
205
What is syntactic sugar?
Syntax to make things more readable
206
What is the typeof an ES6 class?
function
207
Describe ES6 class syntax.
class { constructor(){} methods() }
208
What is refactoring?
restructure code to be more legible, or improve design, WITHOUT changing its functionality
209
How are ES modules different from CommonJS modules?
ES6 is pre-parsed | CommonJS load dependencies on demand
210
What is React?
A front-end javascript library
211
What is a React element?
JSX, object like a DOM node
212
How do you mount a React element to the DOM?
ReactDOM.render
213
What is Babel?
Toolchain made to convert ES6 to ES5
214
What is a Plug-in?
Component that adds a feature
215
What is a Webpack loader?
transformations that are applied to the sources code of a module
216
How can you make Babel and Webpack work together?
babel-loader
217
What is JSX?
Syntax extension
218
Why must the React object be imported when authorizing JSX in a module?
JSX compiles into calls to React.createElement()
219
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
plugin-transform-react-jsx
220
What are props in react?
Dynamic data. Properties to add into your component
221
How do you pass props to a component?
Add it as a parameter, then user {props.`name`}
222
How do you write JavaScript expressions in JSX?
{}
223
How do you create "class" component in React?
extends React.Component
224
How do you access props in a class component?
this.props
225
What is the purpose of state in React?
to have different dynamic data
226
How do you pass an event handler to a React element?
bind this, attribute
227
What Array method is commonly used to create a list of React elements?
Map
228
What is the best value to use as a "key" prop when rendering lists?
Index or ID
229
What are controlled components?
When a components input value is driven by React state
230
What two props must you pass to an input for it to be controlled?
handleChange, handleSubmit
231
What does express.static() return?
middleware
232
What is the local __dirname variable in a node.js module?
directory name of the current module
233
What does the join() method of Node's path module do?
Join path segments
234
What does fetch() return?
promise
235
What is the default request method used by fetch()?
get
236
How do you specify the request method (GET, POST, etc) when calling fetch?
Create a request with the necessary headers
237
When does React call a component's componentDidMount method?
After a component is mounted
238
name 3 React.Component lifecycle methods
ComponentDidMount, DidUpdate, WillUnMount
239
How do you pass data to a child component?
props
240
What must the return value of myFunction be if the following expression is possible? myFunction()();
function
241
``` What does this code do? const wrap = value => () => value; ```
wrap is equal to value value is = to function that returns value. const wrap = value value = function () { return value} function that calls another function that returns the parameter
242
In JavaScript, when is a function's scope determined; when it is called or when it is defined?
defined
243
What allows javascript functions to remember values from their surroundings?
Closures