JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store data

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

How do you declare a variable?

A

use keyword “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 variable = something

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

letter, digits, underscore, dollar signs

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

they must be recalled exactly as they were saved

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 and 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 and manipulate 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 register something as true or 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

it is assigning a value to a variable name

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

What is the difference between null and undefined?

A

null is intentionally given a non-existing value, undefined unintentionally lacks a value

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

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

A

so that you have a better idea of what issues may have occurred when debugging

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

Give five examples of JavaScript primitives.

A

string, number, boolean, undefined, null

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

to update a variable

A

use variable followed by value… don’t need to use ‘var’ again

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

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 combining of two or more strings

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

it adds a value to another variable/value

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 a variable and re-assigns the variable

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

What are objects used for?

A

group together 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

a variable 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

a saved variable followed by curly brace with key-value properties and methods (functions)

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 then object.property

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

either dot 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

storing a list of values

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

Describe array literal notation.

A

var name = [skhf,fskdjhf,skdjfh]

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

How are arrays different from “plain” objects?

A

do not use colons, do not use curly braces, etc
arrays are indexed, objects aren’t

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

What number represents the first index of an array?

A

0

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

What is the length property of an array?

A

array.length… tells you how many items are listed

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

How do you calculate the last index of an array?

A

array.length - 1

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

What is a function in JavaScript?

A

a set of statements that perform a task or calculate a value based off their parameters, and code block

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

Describe the parts of a function definition.

A

parts of a function definition include function name, parameters/arguments, curly brace, optional return statement, and the code

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

Describe the parts of a function definition.

A

parts of a function definition include function name, parameters/arguments, curly brace, optional return statement, and the code

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

Describe the parts of a function call.

A

functionName(optional arguments)

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

When comparing them side-by-side, what are the differences between a function call and a function definition?

A

no function key word and no brackets in function call… definition does have it

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

What is the difference between a parameter and an argument?

A

parameter has no value while argument does

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

Why are function parameters useful?

A

to tell you what type of value to input into a function

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

What two effects does a return statement have on the behavior of a function?

A

stops the code from running any longer, causes function to produce a value we can use in our program

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

Why do we log things to the console?

A

so that we can see the output of our code and make sure things are functioning properly

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

What is a method?

A

a function which is a property of an object…. essentially a built in function

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

How is a method different from any other function?

A

property of an object while other functions are hanging in space

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

How do you remove the last element from an array?

A

.pop() method

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

How do you round a number down to the nearest integer?

A

Math.floor() method

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

How do you generate a random number?

A

Math.random() method

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

How do you delete an element from an array?

A

.splice(1,0) method

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

How do you append an element to an array?

A

.push() method

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

How do you break a string up into an array?

A

.split() method

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

Do string methods change the original string? How would you check if you weren’t sure?

A

no, you assign the value of the string method response to a new variable and call the original string if you want to see it

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

Roughly how many string methods are there according to the MDN Web docs?

A

Around 50

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

roughly how many array methods are there according to the MDN web docs

A

40-50

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

What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?

A

MDN

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

is a return value useful in every situation

A

not necessarily, you might just pop something off an array and thats it

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

Give 6 examples of comparison operators.

A

< > <= >= != = ===etc

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

What data type do comparison expressions evaluate to?

A

booleans (true or false)

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

What is the purpose of an if statement?

A

if that condition is met, then run the following code

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

Is else required in order to use an if statement?

A

no

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

Describe the syntax (structure) of an if statement.

A

if keyword followed by parentheses, rule, curly brace, code

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

What are the three logical operators?

A

“and” “or”, and “not”

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

How do you compare two different expressions in the same condition?

A

have both expressions in the same parenthesis

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

What is the purpose of a loop?

A

run repeated code under specific conditions

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

What is the purpose of a condition expression in a loop?

A

tells you requirements on if the loop should run and how long the loop should be run

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

What does “iteration” mean in the context of loops?

A

each “time” the code is executed

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

When does the condition expression of a while loop get evaluated?

A

beginning of each iteration

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

When does the initialization expression of a for loop get evaluated?

A

the start of the loop

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

When does the condition expression of a for loop get evaluated?

A

after initialization at first, then after every iteration

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

When does the final expression of a for loop get evaluated?

A

after the iteration

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

Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?

A

break keyword

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

What does the ++ increment operator do?

A

increments by 1

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

How do you iterate through the keys of an object?

A

for-in loop

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

Why do we log things to the console?

A

so that we can see the output of our actions

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

What is a “model”?

A

recreation of something

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

Which “document” is being referred to in the phrase Document Object Model?

A

the html document

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

What is the word “object” referring to in the phrase Document Object Model?

A

every tree node… the separate parts of the html

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

What is a DOM Tree?

A

a layout of all html objects

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

Give two examples of document methods that retrieve a single element from the DOM.

A

document.getElementById()
document.querySelector()

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

Give one example of a document method that retrieves multiple elements from the DOM at once.

A

document.getElementsByClassName()
document.querySelectorAll()

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

Why might you want to assign the return value of a DOM query to a variable?

A

so that you can call that variable and change another attribute about it…. or just to refer back to it

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

What console method allows you to inspect the properties of a DOM element object?

A

console.dir()

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

Why would a

 tag need to be placed at the bottom of the HTML content instead of at the top?
A

code is executed line by line so it being at the top will slow down page rendering

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

What does document.querySelector() take as its argument and what does it return?

A

argument: css selector
returns: first matching element

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

What does document.querySelectorAll() take as its argument and what does it return?

A

argument: css selector
returns: all matching elements

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

What is the purpose of events and event handling?

A

so that when a specific event has occurred, we can have a desired outcome

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

Are all possible parameters required to use a JavaScript method or function?

A

no, they can be called anonymously

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

What method of element objects lets you set up a function to be called when a specific type of event occurs?

A

addEventListener()

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

What is a callback function?

A

a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

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

What object is passed into an event listener callback when the event fires?

A

event object

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

What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?

A

the element being selected…
can console.log(event.target)

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

What is the difference between these two snippets of code?

A

one of these will actually call the function the other will not

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

What is the className property of element objects?

A

it has access to the name of the class

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

How do you update the CSS class attribute of an element using JavaScript?

A

element.className = ‘sdfs’

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

How do you update the text within an element using JavaScript?

A

element.textContent = ‘dsgs’

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

Is the event parameter of an event listener callback always useful?

A

useful but not always required…. not always gonna be doing something with it

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

Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?

A

more complicated

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

Why is storing information about a program in variables better than only storing it in the DOM?

A

so that we, and other code readers have a better idea of the importance of each variable and its corresponding actions

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

What does the transform property do?

A

manipulate elements in css

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

Give four examples of CSS transform functions.

A

rotate, scale, skew, translate

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

The transition property is shorthand for which four CSS properties?

A

transition-property, transition-duration, transition-timing-function, and transition-delay

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

What event is fired when a user places their cursor in a form control?

A

focus

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

What event is fired when a user’s cursor leaves a form control?

A

blur

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

What event is fired as a user changes the value of a form control?

A

input

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

What event is fired when a user clicks the “submit” button within a <form>?

A

submit

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

What does the event.preventDefault() method do?

A

prevents browser from automatically reloading page with form values in the url…. depends default behavior of event

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

What does submitting a form without event.preventDefault() do?

A

form values will be in the URL… default behavior will occur… reload the form/page

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

What property of a form element object contains all of the form’s controls.

A

.elements

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

What property of a form control object gets and sets its value?

A

value

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

What is one risk of writing a lot of code without checking to see if it works so far?

A

code may work improperly and you will struggle more to find the solution

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

What is an advantage of having your console open when writing a JavaScript program?

A

can see the output of your code

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

Does the document.createElement() method insert a new element into the page?

A

no, you must append the element for it to be included in the document

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

How do you add an element as a child to another element?

A

element.appendChild()

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

What do you pass as the arguments to the element.setAttribute() method?

A

element.setAttribute(‘name’, ‘value’)

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

What steps do you need to take in order to insert a new element into the page?

A

document.createElement, then append that to the actual pages element

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

What is the textContent property of an element object for?

A

to create/manipulate actual text

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

Name two ways to set the class attribute of a DOM element.

A

.setAttribute() and .className = ‘’

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

What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?

A

you can call that function to over and over again without redoing all the code,
and reusability

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

Give two examples of media features that you can query in an @media rule.

A

min-width and max-width

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

Which HTML meta tag is used in mobile-responsive web pages?

A

<meta></meta>

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

What is the event.target?

A

the full element being selected

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

Why is it possible to listen for events on one element that actually happen its descendent elements?

A

event bubbling goes from child up to parent

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

What DOM element property tells you what type of element it is?

A

event.tagName()

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

What does the element.closest() method take as its argument and what does it return?

A

parameter is what you are looking for and it returns the closest ancestor that meets that criteria

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

How can you remove an element from the DOM?

A

element.remove()

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

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?

A

add event listener to the parent and search for event target with the wanted tag name

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

What is the event.target?

A

the actual target of the event listener

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

What is the affect of setting an element to display: none?

A

it will not be visible

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

What does the element.matches() method take as an argument and what does it return?

A

takes css selector
returns boolean

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

How can you retrieve the value of an element’s attribute?

A

.getAttribute()

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

At what steps of the solution would it be helpful to log things to the console?

A

after every step

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

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?

A

you would listen for each tab click directly

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

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?

A

use if-else statements

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

What is a breakpoint in responsive Web design?

A

the point in which we want the css changes

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

What is the advantage of using a percentage (e.g. 50%) width instead of a fixed (e.g. px) width for a “column” class in a responsive layout?

A

it is relative to the screen size (tablet, phone, etc)

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

If you introduce CSS rules for a smaller min-width after the styles for a larger min-width in your style sheet, the CSS rules for the smaller min-width will “win”. Why is that?

A

because css is read from top to bottom

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

What is JSON?

A

data format that takes form of string and syntax of javascript object

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

What are serialization and deserialization?

A

Serialization is the process of 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.
Deserialization is the reverse process: turning a stream of bytes into an object in memory.

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

Why are serialization and deserialization useful?

A

because it allows you to universally transmit data

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

How do you serialize a data structure into a JSON string using JavaScript?

A

JSON.stringify()

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

How do you deserialize a JSON string into a data structure using JavaScript?

A

JSON.parse()

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

How do you store data in localStorage?

A

localStorage.setItem()

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

How do you retrieve data from localStorage?

A

localStorage.getItem()

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

What data type can localStorage save in the browser?

A

JSON string

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

When does the ‘beforeunload’ event fire on the window object?

A

before the window, document being unloaded/ refreshed or everything is about to get taken off the page

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

What is a method?

A

a function which is a property of an object

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

How can you tell the difference between a method definition and a method call?

A

method definition is a property with the function assigned, method call is object name with the property called on it ()

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

Describe method definition syntax (structure).

A

methodName, function() { code }

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

Describe method call syntax (structure).

A

object.method()

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

How is a method different from any other function?

A

it is a property of an object

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

What is the defining characteristic of Object-Oriented Programming?

A

contains data as properties, and behaviors as methods

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

What are the four “principles” of Object-Oriented Programming?

A

abstraction, encapsulation, inheritance, polymorphism

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

What is “abstraction”?

A

working with complex things in simple ways

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

What does API stand for?

A

application programming interface

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

What is the purpose of an API?

A

give users a way to interact with the system in a simplified efficient way
easy way to get and transmit data easily

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

What is this in JavaScript?

A

a reference to the object being used in javascript… if there is nothing to the left of the dot, then it is referring to the window

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

What does it mean to say that this is an “implicit parameter”?

A

it is not explicitly expressed in the functions parameters/arguments but you still have access to it

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

When is the value of this determined in a function; call time or definition time?

A

at call time

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

What does this refer to in the following code snippet?
var character = {
firstName: ‘Mario’,
greet: function () {
var message = ‘It's-a-me, ‘ + this.firstName + ‘!’;
console.log(message);
}
};

A

the window, until we call it with character.greet

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

Given the above character object, what is the result of the following code snippet? Why?
character.greet();

A

it should return the string

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

var hello = character.greet;
hello();

A

its a mee, then undefined

157
Q

How can you tell what the value of this will be for a particular function or method definition?

A

we don’t know until the specific method gets called

158
Q

How can you tell what the value of this is for a particular function or method call?

A

looking to see if there is something to the left of the dot

159
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based inheritance

160
Q

What is a prototype in JavaScript?

A

an object with certain behaviors (methods) or data (properties) that can be used by other objects

161
Q

How is it possible to call methods on strings, arrays, and numbers even though those methods don’t actually exist on strings, arrays, and numbers?

A

they have inherited it from the prototype chain

162
Q

If an object does not have its own property or method by a given key, where does JavaScript look for it?

A

since prototypes are objects, and objects are referenced data types, the prototype chain is where JavaScript will look for it

163
Q

What does the new operator do?

A

allows you to create an instance of a user-defined object
creates blank javascript object, points the new objects prototype to the prototype object of the constructor function, executes the constructor function, (not-as-important) if constructor function returns a non primitive, the return value becomes the result of the whole new expression

164
Q

What property of JavaScript functions can store shared behavior for instances created with new?

A

prototype

165
Q

What does the instanceof operator do?

A

tests to see if the prototype property of a constructor appears anywhere in the prototype chain of an object

166
Q

What is a “callback” function?

A

a function passed into another function as an argument

167
Q

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?

A

using setTimeout()

168
Q

How can you set up a function to be called repeatedly without using a loop?

A

setInterval()

169
Q

What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?

A

0 milliseconds

170
Q

What do setTimeout() and setInterval() return?

A

returns an interval ID so you can remove it with clearInterval() later on

171
Q

What is a client?

A

The service requestor

172
Q

What is a server?

A

the providers of a resource/service

173
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET request

174
Q

What three things are on the start-line of an HTTP request message?

A

HTTP method, a verb (GET,PUT,POST) or noun (HEAD, OPTIONS)
Request Target (URLs) and domain
HTTP version to define structure of remaining message

175
Q

What three things are on the start-line of an HTTP response message?

A

The protocol version, usually HTTP/1.1.
A status code, indicating success or failure of the request. Common status codes are 200, 404, or 302
A status text. A brief, purely informational, textual description of the status code to help a human understand the HTTP message.

176
Q

What are HTTP headers?

A

case sensitive string followed by a colon… place to send info between request and response

177
Q

Where would you go if you wanted to learn more about a specific HTTP Header?

A

mdn

178
Q

Is a body required for a valid HTTP request or response message?

A

no

179
Q

What is AJAX?

A

a technique for loading data into a part of a page… grab info from server without having to refresh the page

180
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript and XML

181
Q

Which object is built into the browser for making HTTP requests in JavaScript?

A

XMLHttpRequest()

182
Q

What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?

A

load event

183
Q

Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?

A

prototype inheritance

184
Q

What is a code block? What are some examples of a code block?

A

a code block is the area of code within curly braces of a function

185
Q

What does block scope mean?

A

it means to be within that functions codeblock… if its in the codeblock it stays there

186
Q

What is the scope of a variable declared with const or let?

A

block-scoped variables… stay inside their codeblock

187
Q

What is the difference between let and const?

A

let can be reassigned/updated but const cannot

188
Q

Why is it possible to .push() a new value into a const variable that points to an Array?

A

changing contents but not reassigning

189
Q

How should you decide on which type of declaration to use?

A

always use const then if you have to, use let

190
Q

What is the syntax for writing a template literal?

A

${valueofsomethin}

191
Q

What is “string interpolation”?

A

the ability to substitute part of the string for the values of variables or expressions.

192
Q

What is destructuring, conceptually?

A

taking apart an object or array for its properties
and assigns to a variable

193
Q

What is the syntax for Object destructuring?

A

const {item1, item2, item3} = book1

194
Q

What is the syntax for Array destructuring?

A

const [book3, book4, book5] = library

195
Q

How can you tell the difference between destructuring and creating Object/Array literals?

A

destructuring is before curly brace creating is after the brace

196
Q

What is the syntax for defining an arrow function?

A

(variable) => {} or no brackets
variable => {}

197
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

it automatically returns what is in that line

198
Q

How is the value of this determined within an arrow function?

A

if it is within an arrow function then it’ll look for a parent object to refer to

199
Q

What is a CLI?

A

command line interface: receives commands from user in form of lines/text in terminal

200
Q

What is a GUI?

A

graphical user interface: navigate through icons rather than text information

201
Q

Give at least one use case for each of the commands listed in this exercise.
man
cat
ls
pwd
echo
touch
mkdir
mv
rm
cp

A

man: manual for each command need to know more on how to use command
cat: contents of that file printed to terminal
ls: list of items printed into terminal (alot)
ls-a will give you the hidden files
ls-l gives you more detailed info
pwd: prints name of current working directory
echo: display a line of text into terminal that you typed out
touch: change file timestamps: create a file
mkdir: create a directory
mv: rename/move files
rm: delete files or empty directories
(if you do rm -i then itll ask for confirmation)
cp: copy files/directories

202
Q

What are the three virtues of a great programmer?

A

laziness, humorous and something else i forgot

203
Q

What are the 3 components of a fullstack Web architecture?

A

front end, back end, and database

204
Q

What is Node.js?

A

javascript run time for back-end and server that things talk to
a server side program which executes javascript code

205
Q

What can Node.js be used for?

A

running web applications outside the clients browser on the server

206
Q

What is a REPL?

A

takes single user inputs, executes them, and returns the result
(read eval print loop)

207
Q

When was Node.js created?

A

2009

208
Q

What backend languages have you heard of?

A

PHP Java PHP Ruby C++

209
Q

What is a computer process?

A

instance of computer program that is being executed by one more many threads
multiple ‘things’ running in activity monitor that are consuming resources and doing stuff

210
Q

Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?

A

100’s

211
Q

Why should a full stack Web developer know that computer processes exist?

A

since you are running a browser(react), server(serving react), database, and node, you must know the communications that are happening amongst all of them

212
Q

What is the process object in a Node.js program?

A

global that provides info about, and control over, the current node.js process

213
Q

How do you access the process object in a Node.js program?

A

process.argv

214
Q

What is the data type of process.argv in Node.js?

A

array of strings

215
Q

How do you access the command line arguments in a Node.js program?

A

at index of the argument

216
Q

What is a JavaScript module?

A

a single .js file

217
Q

What are the advantages of modular programming?

A

organizing different modules for different purposes… breaking down larger programs into smaller ones

218
Q

In JavaScript, how do you make a function in a module available to other modules?

A

export it

219
Q

In JavaScript, how do you use a function from another module?

A

import

220
Q

What is the JavaScript Event Loop?

A

event loop look at stack and task queue, if the stack is empty, it takes the first thing on task queue and pushes it onto the stack.
executes each task on the queue 1 by 1
when you write something in code and want to do asynchronously, but something in que then move on
setTimeout goes into queue and other things keep running then setTimeout comes after

221
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

blocking (synchronous) is code that is slow/ on a long stack doesnt allow other lines of code to happen… solved by asynchronous call backs
non-blocking is put on the queue and executes when it gets a chance… it is asynchronous
asynchronous can run out of order
synchronous is in order

222
Q

What are the three states a Promise can be in?

A

pending: initial state, neither fulfilled nor rejected
fulfilled: operation was completed successfully
rejected: operation failed

223
Q

How do you handle the fulfillment of a Promise?

A

.then

224
Q

How do you handle the rejection of a Promise?

A

.catch

225
Q

What does Array.filter do?

A

creates a ‘shallow copy’ of a portion of an array… filtered down to just the elements of the array that pass the test of the function

226
Q

What should the callback function return?

A

returns boolean… if its true then it returns the elements which pass the test of the function into the array

227
Q

What is Array.filter useful for?

A

finding only elements in an array that match a specific criteria

228
Q

What does Array.map do?

A

manipulates every element in an array and returns the new manipulated array… doesn’t modify original array

229
Q

What should the callback function return?

A

the new manipulated array

230
Q

What is Array.map useful for?

A

manipulating every element in an array

231
Q

What does Array.reduce do?

A

executes a user-supplied “reducer” callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element.
(walks through an array and reduces it into a single value)

232
Q

What action should the callback function perform?

A

calculation of the value of the preceding element… computation of an element, then adds to the accumulated value

233
Q

What should the callback function return?

A

returns the accumulated value

234
Q

What is Array.reduce useful for?

A

using multiple elements in an array to calculate amongst each other

235
Q

What is a directory?

A

a folder

236
Q

What is a relative file path?

A

a path to get to something relative to where you are

237
Q

What is an absolute file path?

A

a path that gets you to the same destination no matter where you are

238
Q

What module does Node.js include for manipulating the file system?

A

fs
readFile(path, ‘utf8’)

239
Q

What method is available in the node:fs module for writing data to a file?

A

writeFile

240
Q

What method is available in the node:fs module for writing data to a file?

A

writeFile

241
Q

Are file operations using the fs module synchronous or asynchronous?

A

Asynchronous

242
Q

What is a client?

A

whoever is requesting a service

243
Q

What is a server?

A

whoever is providing the service

244
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

HTTP GET Request

245
Q

What is on the first line of an HTTP request message?

A

HTTP method (get, post, put, etc)
Request Target
HTTP version

246
Q

What is on the first line of an HTTP response message?

A

Protocol Version
Status Code
Status Text

247
Q

What are HTTP headers?

A

a case-insensitive string followed by a colon (‘:’) and a value whose structure depends upon the type of the header. The whole header, including its value, presents as a single line.

248
Q

Is a body required for a valid HTTP message?

A

no

249
Q

What is NPM?

A

Node packaging manager… allows us to share and borrow packages

250
Q

What is a package?

A

chunk of code that you can reuse

251
Q

How can you create a package.json with npm?

A

npm init –yes

252
Q

What is a dependency and how do you add one to a package?

A

packages that are required by your application in production

253
Q

What happens when you add a dependency to a package with npm?

A

they get stored in the package.json file and it creates a node module directory in the root directory, and it installs the info into your node modules….

254
Q

What are some other popular package managers?

A

Yarn and PNPM

255
Q

What is Express useful for?

A

help manage routes and endpoints
manages the http requests

256
Q

How does Express fit into a full-stack web application?

A

serves as middleman between front and back end communication… manages the http requests

257
Q

How do you add express to your package dependencies?

A

npm install express

258
Q

What Express application method starts the server and binds it to a network PORT?

A

app.listen… the port is where you are listening for the request… port number is often used to identify specific services

259
Q

What is Express middleware?

A

set of functions that execute when an http request is made by an express application

260
Q

What is Express middleware useful for?

A

processing http requests by express apps
sits in between the response and request

261
Q

How do you mount a middleware with an Express application?

A

pass the function through app.use

262
Q

Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

request, response, and next function

263
Q

What is an API endpoint?

A

takes you to a specific collection of data
end point is between the two first slashes essentially

264
Q

What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?

A

application/json

265
Q

What is the significance of an HTTP request’s method?

A

dictates whether you will be getting, adding, or deleting info

266
Q

What does the express.json() middleware do and when would you need it?

A

parses the JSON… new body with parsed data is populated on the request object

267
Q

Why do we use databases in Web development?

A

application needs to quickly retrieve or store complex data in an organized fashion, a database fills that need nicely… easier to query, organize, etc… data is less likely to get stolen…. can also store way more info… and much more

268
Q

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a powerful, free, open source Relational Database Management System (RDBMS).

269
Q

What are some advantages of learning a relational database?

A

help with data integrity… when making applications you need a place to store and manipulate data

270
Q

What is one way to see if PostgreSQL is running?

A

either top command or sudo service postgresql status

271
Q

What is a database schema?

A

organized collection of tables which describes your data

272
Q

What is a table?

A

relational databases store data here… each row will have the same columns

273
Q

What is a row?

A

has the same set of attributes

274
Q

What is an attribute and what other names are used to describe them?

A

also called columns… they are a set of factors describing something

275
Q

What is SQL and how is it different from languages like JavaScript?

A

it is a declarative programming language meaning you simply declare what you want…. not like normal code

276
Q

How do you retrieve specific columns from a database table?

A

put the column names after select

277
Q

How do you filter rows based on some specific criteria?

A

where clause

278
Q

What are the benefits of formatting your SQL?

A

readability

279
Q

What are four comparison operators that can be used in a where clause?

A

= < > !=

280
Q

How do you limit the number of rows returned in a result set?

A

limit keyword

281
Q

How do you retrieve all columns from a database table?

A

select *

282
Q

How do you control the sort order of a result set?

A

order by

283
Q

How do you add a row to a SQL table?

A

use insert keyword

284
Q

What is a tuple?

A

a list of values inside parenthesis

285
Q

How do you add multiple rows to a SQL table at once?

A

after one row of values include a separate tuple

286
Q

How do you get back the row being inserted into a table without a separate select statement?

A

returning*;

287
Q

How do you update rows in a database table?

A

update set where

288
Q

Why is it important to include a where clause in your update statements?

A

so you update in the proper row

289
Q

How do you delete rows from a database table?

A

delete from where

290
Q

How do you accidentally delete all rows from a table?

A

only saying delete from

291
Q

what is a foreign key

A

a key that references primary key of another table

292
Q

how do you join two SQL tables

A

join “table” using (“something”)

293
Q

How do you temporarily rename columns or tables in a SQL statement?

A

from “products” as “p”

294
Q

What are some examples of aggregate functions?

A
295
Q

What is the purpose of a group by clause?

A
296
Q

What are JavaScript classes?

A

template for creating a new object

297
Q

When would you want to use a class?

A

when wanting to create an object that has similar tendencies to a previous object… when you have some data or a function that you want to encapsulate

298
Q

How do you declare a class?

A

class Name {
}

299
Q

How do you inherit from another class?

A

use super/extends

300
Q

How do you add methods and properties to a class?

A

super.something and this.something

301
Q

How do you add methods and properties to a class?

A

to essentially reuse code from the super class

302
Q

What is Webpack?

A

bundles all code from javascript and npm files that need to be used for your code…. when producing/ final product is being sent it helps

303
Q

What is the advantage of using Webpack (or a similar bundler)?

A

can import only what you need from other node modules

304
Q

What is Babel?

A

translates new cold into old code for apps that use old code

305
Q

What is the advantage of using Babel (or a similar transpiler)?

A

legacy code can still be worked on

306
Q

What is React?

A

builds user interfaces based off components…
a front-end framework which creates reusable components

307
Q

What is a React element?

A

a dom node represented by a component…. basically an element on the screen that can be interacted with

308
Q

How do you mount a React element to the DOM?

A

function App () {
div
header
}

309
Q

What is jsx

A

extension for js where you can write html into js files

310
Q

How does React use JSX to render components

A
311
Q

What is a react component

A

a function to create an element

312
Q

How do you define a component in react

A

capital letter at the beginning of a function name

313
Q

How do you mount a component to the DOM (or “render” a component)

A

takes result of calling component function then adds it to the DOM

314
Q

What are props in React?

A

info being passed from one component to another… correspond to attributes in html

315
Q

How do you use props in a component?

A

call it as parameter and de-structure in the code block

316
Q

How do you pass props to a component?

A

<CustomButton text = {“I”} color={‘Red’} />
can put js expressions

317
Q

How do you write JavaScript expressions in JSX?

A
318
Q

How to you pass an event handler to a React component?

A

pass it as one of the properties to the component

319
Q

What are some custom event handler props a component may wish to define?

A

onclick onchange onsubmit onhover onmouseenter

320
Q

What is the naming convention for custom event handler props?

A

uses the on-prefix

321
Q

what is an event handler prop

A
322
Q

What are hooks in React?

A

defined by the component. used for general event handling… then the parent uses it accordingly

323
Q

What are the “Rules of Hooks”? (if necessary, re-read the “Pitfall” box in State)

A

all start with the same first three letters, followed by an uppercase letter
i.e. ‘useState’
only can be called in react component, or in another hook

324
Q

What is the purpose of state in React?

A

holds data for you between renders/function calls

325
Q

Why can’t we just maintain state in a local variable?

A

the variable will get reset after rendering if its in a local variable… if its in a global variable, it wont render again even if you update it… also we need each instance of a component to have its own copy of its data

326
Q

What two actions happen when you call a state setter function?

A

triggers react to re-render and

327
Q

When does the local state variable get updated with the new value?

A

after useState has been called/ re-render has occured

328
Q

How do controlled components differ from uncontrolled components?

A

if its an uncontrolled component input element is in charge of the value…. if it’s controlled, then the form/parent is in control of the values

329
Q

What are some advantages of using uncontrolled components?

A

uncontrolled is simpler… don’t need use state… less code if you have a lot of fields

330
Q

What are some advantages of using controlled components?

A

UI and data are in sync… if you want something like a live search bar, or anytime multiple components are interacting with each other at the same time you’ll want this

331
Q

Which style do you prefer?

A

idk i’m too new to this to decide

332
Q

What two props must you pass to an input for it to be “controlled”?

A

useState, onChange

333
Q

What are some popular npm packages for creating forms in React?

A

react hook form, react final form

334
Q

When would we want to create a list of React components?

A

when building list based off data, need it to be created dynamically

335
Q

Why is it important for React components to be data-driven?

A

so that only data changes and everything else is created the same based off that data

336
Q

Where in the component code would a list of React components typically be built?

A
337
Q

What Array method is commonly used to create a list of React components?

A

.map()

338
Q

Why do components in a list need to have unique keys?

A

so that react can keep track of them to re-order or remove things when changing the filtering on them

339
Q

What is the best value to use as a “key” prop when rendering lists?

A

an id or #

340
Q

When is a component “mounted” to the DOM?

A

when the component appears for the first time

341
Q

What is a React Effect?

A

a block of code that runs after the rest of the page has rendered

342
Q

When should you use an Effect and when should you not use an Effect?

A

when you want to manage a side effect here you can fetch data or interact with other systems… don’t use it when you can just use useState

343
Q

When do Effects run?

A

after the page renders… then if the dependency changes it runs again

344
Q

What function is used to declare an Effect?

A

useEffect()

345
Q

What are Effect dependencies and how do you declare them?

A

pass it as a second argument in an array… any reference to any variable or function declared inside of component but outside of use effect function is a dependency

346
Q

Why would you want to clean up from an Effect?

A

release resources you have allocated…

347
Q

How do you clean up from an Effect?

A
348
Q

When does the cleanup function run?

A

when you dismount, and before it calls effect again

349
Q

What is the purpose of the Express Static middleware?

A

looks for a file by the same name, serves the contents of that file rather than you manually writing a middleware that shows that

350
Q

What does express.static() return?

A

a middleware function

351
Q

What are several examples of static files?

A

html css js image files… anything you can start up without needing a server
ex js file that you import isn’t a static file

352
Q

What is a good way to serve application images using Express?

A

express.static()

353
Q

What does fetch() return?

A

a promise that resolves with response object

354
Q

What is the default request method used by fetch()?

A

get

355
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

after the link, comma and object with method name

356
Q

How does fetch report errors?

A

throws an exception when there is a network error (unable to get a request to the server)…
if a response comes back, it sets response.ok to true if its between 200-299
sets response.ok to false otherwise… but doesn’t throw so you must try catch and check response.ok

357
Q

How can useEffect be used to load data for a component?

A

when you want to load data after everything else has been rendered

358
Q

What browser function can be used to make HTTP requests to a server in React?

A

fetch

359
Q

How do you use useEffect to load component data just once when the component mounts?

A

empty dependency array

360
Q

How do you use useEffect to load component data every time the data key changes?

A

pass it into the dependency array

361
Q

In a large-scale production app, what are some better alternatives for loading and managing backend data?

A

React Query and Vercel SWR

362
Q

What is the purpose of React “context”?

A

can share information to any component
restrictions: has to be a child… doesn’t have to be direct child but must be a child/nested child

363
Q

What values can be stored in context?

A

anything

364
Q

How do you create context and make it available to the components?

A
365
Q

How do you access the context values?

A
366
Q

What is a React custom hook?

A

a hook you write that calls other hooks

367
Q

When are custom hooks useful? When are they not required?

A

when you don’t want to duplicate code… not useful when it doesn’t call another hook

368
Q

What is the syntax (or naming convention) for writing a custom hook?

A

“use” something with the parameters of whatever you wan’t it to take and returns whatever you want it to take

369
Q

How do you call a custom hook?

A

must be at top level of component, cant be conditionally called

370
Q

When do custom hooks execute?

A

whenever the component is rendered or when they are called

371
Q

What does the acronym LIFO mean?

A

last in first out

372
Q

What methods are available on a Stack data structure?

A

pop, push, peek

373
Q

What must you do to access the value at an arbitrary point in a stack (not just the “top”)?

A
374
Q

What does the acronym FIFO mean?

A
375
Q

What methods are available on a Queue data structure?

A
376
Q

What must you do to access the value at an arbitrary point in a queue (not just the “front”)?

A
377
Q

How are linked lists different from an array?

A

cannot access them at an index… can only go forwards and have access to the very next node

378
Q

How would you access an arbitrary node in a linked list (not just the “head”)?

A

keep calling next until you get to what you want

379
Q

what is a unit test?

A

software that is able to test individual units

380
Q

why is it important to write unit tests

A

good way to debug code, gives you confidence when you are refactoring your code

381
Q

what code should be tested with a unit test? What code is not well suited for unit tests?

A

small unit is good, not good for large application

382
Q

what is jest? what are some other popular javascript unit testing frameworks

A

jest is a unit testing framework, other popular ones are mocha, storybook, etc

383
Q

In JavaScript, when is scope determined?

A

when it is parsed…

384
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

a closure

385
Q

What values does a closure contain?

A

all variables and functions within the parent scope

386
Q

When is a closure created?

A

every time a function reference is created, which is at run time

387
Q

How can you tell if a function will be created as a closure?

A

if it needs any variables outside of itself

388
Q

In React, what is one important case where you need to know if a closure was created?

A