JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store values/information
and we are able to refer/call this variable later!

i.e to store information for the future

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”, “let”, “const”)

followed with the name of variable and end with semicolon “;”
ex) var name;

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

single equal sign (assignment operator)

start with variable name following with an equal sign (=) and the value you want to assign to variable. end with semicolon

ex) Name = “Monique”;

  • but usually will declare and assign variable in one step!!
    ex) var Name = “Monique”;
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

numbers, letters, dollar sign ($), underscore (_)

**but variables cannot start with 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

lowercase and uppercase letters are different (even if its same letter)

(ex) Name, name –> are two different variable names

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 store letters and other characters
a sequence of a set of characters

js wont care about what is in strings

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 store numeric values
(that we usually do calculations with, mathematical operations)

financial information a good example to use numbers but not smt like a zipcode (b/c we arent usually doing mathematical operations with zipcode values)

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

What is the purpose of a boolean?

A

purpose is to make decisions

it is able to represent if something is or isn’t (binary)

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

What does the = operator mean in JavaScript?

A

assignment operator

used to assign a value to a variable
assign: to store information to a variable (name)

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

don’t use keyword!! (if variable already exists)
write variable name with equal sign (assignment operator) and new variable 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

both are value types

null: value that is assigned and purposely/intentionally left blank/empty
value that can only appear b/c DEVELOPER purposely assigned it to something
ex) optional inputs on a website from user (we still need to store data about user, so can use null in the optional inputs user did not fill out)

undefined: value that is assigned by BROWSER
value that can come from anywhere; if undefined pops up, need to investigate?

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 give clarity
to know if the correct value is being assigned to correct variables (debugging or double checking when you go back to code)

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

Give five examples of JavaScript primitives.

A

string, number, boolean, null, undefined

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

What data type is returned by an arithmetic operation?

A

number

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

What is string concatenation?

A

adding two or more strings together to create one string

(addition but for strings)

*concatenation does not change the value of the individual 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

mathematical operations (summing), string concatenation

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

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

A

boolean

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

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

A

shorthand operator
adds a value to an already existing variable and reassigns the resulting value to the same variable

ex) var name = “Monique”;
name += “ Chang”;

   name variable's value would now be Monique Chang, and not Monique
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What are objects used for?

A

to group together data, functions, etc that are related to each other

create multiple groups of organized data
(are able to use same property names for multiple objects)

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

What are object properties?

A

individually named data inside objects
(are variables essentially)

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

Describe object literal notation.

A

object name = { };

object name = {
property name: property value,
property name: property value,
property name: property value
};

*example of key/value pair

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

use delete.”object name”

delete operator

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

use dot notation or bracket notation

objectname.objectpropertyname/key

objectname[“objectpropertyname.key”]

*bracket notation wont work for methods!
*bracket notation useful b/c in dot notation, js perceives anything after dot as a string
so variables, numbers etc cant work with dot notation.

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

. notation code reading
[ ] notation code reading

A

. = “of”
[ ] = “at”

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

What are arrays used for?

A

storing/grouping a set of related values
(helpful when you don’t know how many values there will be)

allows us to group together like data types and put into “lists”
so that they are organized and we can deal with them one at a time

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

Describe array literal notation.

A

array name = [ ];

array name = [
“value”,
“value”,
value
];

*value can be any data type!

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

How are arrays different from “plain” objects?

A

arrays have a order (index numbers; numerically indexed)
no property names (property names are basically the index numbers)
are able to know how many pieces of data is being stored (length property)
need to use method (push) to add data to array (not assign directly like objects)

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

What number represents the first index of an array?

A

zero

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

What is the length property of an array?

A

tells you the length of the array (how many values/items are in the array)
different from index numbers!!

arrayname.length

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

How do you calculate the last index of an array?

A

can use length property to find length of the array and subtract 1 to get last index num of the array
(b/c index numbers start at 0 so the last index number will be length of array minus one)

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

data models

A

objects in arrays
arrays in objects

organizing large chunks of data?

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

What is a function in JavaScript?

A

a block of code that contains set of instructions that gets executed when the function is called

take in values –> spit out values based on values provided
make change to something, somewhere

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

Describe the parts of a function definition.

A

function keyword, optional name, optional parameter(s), code block, optional return word (in code block)

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

Describe the parts of a function call.

A

function name with arguments(may or may not have) in parentheses
*if no arguments, still need ( )

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

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

A

function call: function name, arguments

function definition: function keyword, parameters, code block,

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

What is the difference between a parameter and an argument?

A

parameter: placeholder for arguments

argument: what you actually put into function to execute the code

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

Why are function parameters useful?

A

parameters give us the ability to have mutability based on data

don’t have to write multiple functions

gives us functionality

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

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

A

Causes the function to produce a value we can use

Prevents any more code in the function’s code block from being run entirely.
(even if theres more code after return statement in the code block)

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

an expression in JS

A

needs to be evaluated to reach a value

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

Why do we log things to the console?

A

debugging tool

double check code, but soley to check

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

What is a method?

A

a type of function

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

How is a method different from any other function?

A

methods are attached to objects

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

How do you remove the last element from an array?

A

pop( ) method

*will return that element you removed

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

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

A

Math.floor ( )

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

How do you generate a random number?

A

Math.random( );

0 to 1 (but 1 isn’t included)

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

How do you delete an element from an array?

A

splice method

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

How do you append an element to an array?

A

push method

*returns length of array
*append means to add at the end

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

How do you break a string up into an array?

A

split method

*returns an array

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

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

A

no they do not

can use console.log(“the string”) to check

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

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

A

a lot!

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

Is the return value of a function or method useful in every situation?

A

not always

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

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

A

a lot!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
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
54
Q

Give 6 examples of comparison operators.

A

<, >, ===, !==, >=, <=

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

What data type do comparison expressions evaluate to?

A

booleans

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

What is the purpose of an if statement?

A

to check condition to decide whether to run a certain code block or not

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

Is else required in order to use an if statement?

A

no

*if else is included means something will always happen
we dont necessarily want something to occur always

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

Describe the syntax (structure) of an if statement.

A

if keyword, condition, code block

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

What are the three logical operators?

A

and(&&), or ( | | ), not ( ! )

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

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

A

use “and” or “or”

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

truthy values and falsey values (for conditionals)

A

truthy: assumed to have values
*infinte amount of truthy values (everything that is not truthy)

falsey: emptiness

*(not that many)
false, 0, empty strings, null, undefined, NaN

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

What is the purpose of a loop?

A

a set of code can be run over and over again

gives us ability to repeat functionality

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

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

A

if condition is met: loop continues
if condition is not met: loop stops

what decides when to stop a loop

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

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

A

one time a loop code block is run

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

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

A

before code block is executed (before each itieration)

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

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

A

one time before everything

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

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

A

during first iteration: after initialization
during every following iteration: right at start of loop (before code block runs) / after final expression

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

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

A

before the condition runs again
after the code block runs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
69
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

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

What does the ++ increment operator do?

A

adds one to the variable it is applied to (and saves that value in that variable)

*count++ : using count and then incrementing
*++count : incrementing count value before using

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

How do you iterate through the keys of an object?

A

use for in loop

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

Why do we log things to the console?

A

debugging, checking if certain code works properly. etc.

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

What is a “model”?

A

representation of something

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

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

A

the html document (document that represents the entire page)

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

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

A

JS objects (b/c DOM tree is made of objects)

Document Object Model: is a JavaScript object modeling the HTML document’s content

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

What is a DOM Tree?

A

form of organization of data

all data necessary to make a single element and all of it’s content (child elements, attributes, etc)

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

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

A

getElementById( ), querySelector( )

*querySelector( ) use this!!!!!!

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

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

A

getElementsByClassName( ), getElementsByTagName( ), querySelectorAll( )

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

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

A

if you are going to use the return value of the DOM query again (multiple times)
don’t have to keep searching for it each time u use it

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

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

A

console.dir( )

dir = directory

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

Why would a tag need to be placed at the bottom of the HTML content instead of at the top?

A

HTML document loads code from top to bottom, so need to put at bottom so body element needs to load first

the browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.

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

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

A

argument: css selector

returns: first element with the argument css selector

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

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

A

argument: css selector

returns: all elements with the argument css selector (in a NodeList)

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

NodeList

A

looks like an array but is not the same

its an array-like object (but cant adjust like an array)

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

What is the purpose of events and event handling?

A

events: to be aware when certain action happens

event handling: to allow us to do smt in response to event (interactiveness)

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

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

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
87
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
88
Q

What is a callback function?

A

a function passed as an argument in another function

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

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

A

event object

a object js makes that holds all relevant info about that certain event (when it is fired)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
90
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 place event occurred from

use inspect or mdn

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

What is the difference between these two snippets of code?
element.addEventListener(‘click’, handleClick)
element.addEventListener(‘click’, handleClick())

A

handleClick executes when event happens

handleClick( ) is being called right when page loads
code in function code block isn’t correct
and when you click button, returns undefined (so nothing happens)

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

What is the className property of element objects?

A

property that contains value of class attribute of that element

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

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

A

use className property to change value of the class attribute of that element

get element -> assign new value (using assignment operator)

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

What is the textContent property of element objects?

A

property that contains text content of certain element

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

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

A

use textContent property to change text content (using assignment operator)

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

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

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
97
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
98
Q

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

A

easy access to elements w/o having to query/search for it everytime

data is readily accessible in the language we are writing
better to use data w/in language you are working with

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
99
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
100
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
101
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
102
Q

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

A

submit

submit event is an event on FORM element, NOT submit button(submit button triggers event)

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

What does the event.preventDefault() method do?

A

prevents default action for an event from being taken as it normally would be.

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

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

A

automatically reloads page

preventDefault will always be present when using submit events

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
105
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
106
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
107
Q

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

A

missing errors and having to now go through a lot of code to fix errors

not catching errors early and not being able to see clearly where error is from

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

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

A

can see how certain code affects webpage/browser in live time
can check code right away

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

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

A

no

110
Q

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

A

appendChild( ) method

111
Q

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

A

the attribute name and value

example: (“class”, “column-full”)

112
Q

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

A

create element, append element to parent element u want to using appendChild( )

113
Q

What is the textContent property of an element object for?

A

add/set text to element
check what text content of element is of an element

114
Q

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

A

element.className( )
element.setAttribute( )

115
Q

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

A

can reuse function:
call function again to make same structure
use function in multiple different contexts/situation

116
Q

What is the event.target?

A

property on event object that tells the event originated from (whereever the event occured)

117
Q

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

A

event bubbling

118
Q

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

A

tagName

nodeName(less specific)

119
Q

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

A

argument: css selector
return: closest ancestor that matches the argument css selector

*opposite of querySelector (b/c closest searches outward while querySelector searches within)

120
Q

How can you remove an element from the DOM?

A

remove( )

on dom object we want to remove

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 parent

122
Q

What is the event.target?

A

property on the event object which stores a ref to the dom element where event originated from

123
Q

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

A

element is no longer visible

removes element from document flow

124
Q

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

A

argument: css selector(s) as a string

return: boolean stating whether the argument selector(s) match the ones of the element (true)
(false) if the argument selectors do not match those of the element

125
Q

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

A

element.getAttribute( )

attribute name as a string goes in ( ) and the return is the value of that attribute

126
Q

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

A

as often as possible!

anytime u need to check anything

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

need to add individual event listeners to each tab and view

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

long conditional block
conditional blocks for every single view

129
Q

What is JSON?

A

JavaScript Object Notation

format for rendering data that follows norms of a JS object

*cant store objects or array long term but u can w/ strings so we utilize this

130
Q

What are serialization and deserialization?

A

serialization: get data and turn into one piece of data to store easily (ease of analysis) (packing stuff in one suitcase for trip)

deserialization: get data that is serialized and turn back into more complicated pieces of data that is easily accessible and can grow (might not all be in once place)
(unpacking everything after trip (so that everything is more accessible than keeping in suitcase)

131
Q

Why are serialization and deserialization useful?

A

serialization: data good for long term storage and transmission

deserialization: good for interaction with data

132
Q

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

A

JSON.stringify( )

133
Q

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

A

JSON.parse( )

134
Q

How do you store data in localStorage?

A

localStorage.setItem( )

argument: keyname , keyvalue

135
Q

How do you retrieve data from localStorage?

A

localStorage.getItem( )

arguement: is the keyname as a string

136
Q

What data type can localStorage save in the browser?

A

strings (thats why we learned JSON)

137
Q

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

A

right before window document is about to be unloaded

close tab, refresh tab, close browser, browser crashes

138
Q

What is a method?

A

function that is stored as a a property of an object

139
Q

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

A

method def:: has function code block, has colon, and ‘function’ keyword

method call: object name, arguments, property name

140
Q

Describe method definition syntax (structure).

A

object name {
property name: function def(can have name or not) (parameter(s)) {
//function code block
}
};

141
Q

Describe method call syntax (structure).

A

object.method(arguments);

142
Q

How is a method different from any other function?

A

methods are attatched to an object
need to state object to use methods

143
Q

What is the defining characteristic of Object-Oriented Programming?

A

objects can contain both data (as properties) and behavior (as methods).

144
Q

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

A

abstraction, encapsulation, inheritance, polymorphism

145
Q

What is “abstraction”?

A

to being able to work with (possibly) complex things in simple ways
process of reducing complexity

146
Q

What does API stand for?

A

application programming interface

147
Q

What is the purpose of an API?

A

to give programmers a way to interact with a system in a simplified, consistent fashion: aka, an abstraction

148
Q

What is this in JavaScript?

A

implicit parameter that allows us to view object from where this method is being used

149
Q

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

A

always there, even if you don’t write it in parameter list
are able to get value
implied value that is always present

150
Q

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

A

call time!!!

151
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

value of this: nothing!

greet function has not been called yet, ‘this’ is determined during call time, NOT definition time

152
Q

var character = {
firstName: ‘Mario’,
greet: function () {
var message = ‘It's-a-me, ‘ + this.firstName + ‘!’;
console.log(message);
}
};

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

A

greet function is now being called, so ‘this’ is:
It’s-a-me, Mario!

153
Q

var character = {
firstName: ‘Mario’,
greet: function () {
var message = ‘It's-a-me, ‘ + this.firstName + ‘!’;
console.log(message);
}
};

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

A

It’s-a-me, undefined!

hello() is a free floating function with no object to the left, so the object is the window.
window object does not have a property named firstName, so firstName is undefined.

154
Q

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

A

No, w/in definition, cant guarantee ‘this’ will be anything (this is a parameter/placeholder)

155
Q

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

A

whatever is to the left of the dot of method is value of ‘this’
*no dot, then being executed in global scope: so object is window!

156
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance.

157
Q

What is a prototype in JavaScript?

A

object that contains properties that can be used by other objects

a tool that can be passed to many sources to use

158
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 a prototype that has all these methods (where shared behavior is stored)

159
Q

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

A

prototype (if multiple prototypes (prototypal chain), will search from closest to farthest (linear))

160
Q

What does the new operator do?

A

create a empty js object, takes (constructor) function being called’s prototype (prototype property) and adds to empty object( __proto__ or [[prototype]] ), makes empty obj the value of ‘this’ & function codeblock is run, returns object if no other return is specified

constructor functions dont have return values
allows us to invoke a function as a constructor function

161
Q

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

A

prototype

162
Q

What does the instanceof operator do?

A

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

*object instanceof constructor

163
Q

What is a “callback” function?

A

fucntion that is passed as an argument to another function

164
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

setTimeout( )

165
Q

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

A

setInterval( )

166
Q

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

A

0

does not mean action happens immediately, is put in queue immediately

167
Q

What do setTimeout() and setInterval() return?

A

interval ID

168
Q

What is AJAX?

A

programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.
Ajax allows you to update parts of the DOM of an HTML page without the need for a full page refresh. Ajax also lets you work asynchronously, meaning your code continues to run while the targeted part of your web page is trying to reload (compared to synchronously, which blocks your code from running until that part of your page is done reloading).

technique for loading data into a webpage w/o having to reload entire webpage (just reload parts of webpage)
don’t have to go to other pages

169
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

170
Q

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

A

XMLHttpRequest

171
Q

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

A

load event

172
Q

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

A

XMLHttpRequest is a JS object so addEventListener method can be applied

173
Q

ES6 ↓

A
174
Q

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

A

block of code written inbetween curly braces

examples: loops, functions, conditionals

175
Q

What does block scope mean?

A

only exists within a certain code block

so cant access variables declared in block, outside of block

176
Q

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

A

block scope
so variables only exist w/in that code block

*var is function scope, not block scope! (lives/exists past the code block)

177
Q

What is the difference between let and const?

A

let can be reassigned (mutable)
const cannot be reassigned (read only reference; immutable)

178
Q

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

A

the actual value to which the const variable reference is not immutable
even though the Array variable is a constant, you can change its values.
however, you cannot reassign a different value to the Array constant itself

179
Q

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

A

prefer const
(use const until u cant!)

if variable is not being reassigned at anytime in code, should use const
if not, should use let

180
Q

What is the syntax for writing a template literal?

A

same as strings but w/ backticks and not ‘ ‘ or “ “
assign w/ const variable
${expression} if u want to add JS expression into template literal

181
Q

What is “string interpolation”?

A

to create strings by doing substitution of placeholders (syntax: ${})

embed variables and expressions in a string
The JavaScript engine will automatically replace these variables and expressions with their values.

182
Q

What is destructuring, conceptually?

A

assigning properties of an object or array into individual variables.

extracting property values from objects and array element values into new variables

183
Q

What is the syntax for Object destructuring?

A

var/let/const { property1: variable1, property2, etc } = object;

if u want to assign a property value to a variable thats not the same name as property key name, use colon, if not can just put the property key name (like example above)

184
Q

What is the syntax for Array destructuring?

A

const [variable1, variable2, variable3, etc] = array;

variable names correspond to elements in array

185
Q

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

A

curly braces or square bracket will be on left side of = if its destructuring

object/array name we are destructuring from is on right side of assignment operator and not on the left

186
Q

What is the syntax for defining an arrow function?

A

parameter(s) => code;
*if more than one parameter, need ( )
* if more than one statement in code block, need { }

(param1, param2, etc) => {
return;
};

param => expression;

( ) => expression;

187
Q

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

A

evaluated as an expression rather than a statement and has implicit return

188
Q

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

A

lexical scope, takes “this” value from the enclosing function (“parent” function, function that encloses the arrow function)

“this” value is defined when arrow function is DEFINED, and not CALLED like es5!!
opposites!!

189
Q

What is a CLI?

A

command line interface
text based system to interact w/ program

190
Q

What is a GUI?

A

graphical user interface
interact w/ program w/ icons instead of text

191
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: look up manuals for command line commands to see how they work and what options they have
cat: concatenate files
ls: list contents of directories
pwd: prints full file name of current/working directory (where am i right now in my system?)
echo: displays line of text (console.log for terminal kinda)
touch: change/update files’ timestamps (but use mostly to create a file)
mkdir: make a directory
mv: move or rename a file or directory
rm: remove a file or directory (be careful!!)
cp: copy a file or directory

192
Q

What are the three virtues of a great programmer?

A

laziness, impatience, hubris

193
Q

What is Node.js?

A

a program that allows JavaScript to be run outside of a web browser

ex: you have some JS in a file, can use node.js to run that JS in file

194
Q

What can Node.js be used for?

A

used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.

195
Q

What is a REPL?

A

read–eval–print loop
a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user

ex: browser console, bash shell

196
Q

When was Node.js created?

A

2009

197
Q

What back end languages have you heard of?

A

scripting languages (interpreted on-the-fly, garbage collection, dynamic, safer): python, ruby (jit), php, javascript (jit), perl, elixir, erlang
*jit: just in time compilation (interpreter is very sophisticated)

memory managed languages (compiled ahead of time, has garbage collection): java, kotlin c#, golang, haskell, julia, f#, fortan

manual memory management (compiled ahead of time, no garbage collection, low-level, hard but fast, dangerous if done wrong): c++, c, swift, rust, d, zig

sql (for databases)

198
Q

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

A

a global obj that provides information about, and control over, the current Node.js process

199
Q

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

A

‘process’
always available to Node.js applications

200
Q

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

A

array of strings

201
Q

What is a JavaScript module?

A

a single JS file (in JS context)

202
Q

What values are passed into a Node.js module’s local scope?

A

require, module, exports, _filename, _dirname

203
Q

Give two examples of truly global variables in a Node.js program.

A

process, console

204
Q

What is the purpose of module.exports in a Node.js module?

A

require () returns content in module.exports object. So need to put content we want to use in other modules into module.exports in order to access

tells node.js which code to export and use in other modules

205
Q

How do you import functionality into a Node.js module from another Node.js module?

A

use require( ) (pass in relative path to other module we want to access)
assign to variable

return value is value that is assigned to module.exports

206
Q

What is the JavaScript Event Loop?

A

grabs tasks from task queue and pushes onto call stack when call stack is empty
collecting and processing events that is in queue

watches task queue and call stack, when call stack is clear, pushes tasks from task queue onto call stack

207
Q

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

A

blocking: stops future code from executing (synchronous)
occupies call stack (nothing can run while that function is being run (is on call stack))

non-blocking: asynchronous

208
Q

What is a directory?

A

file system object that lists other files and directories
computer “folder”

209
Q

What is a relative file path?

A

path to a file from where you are currently

210
Q

What is an absolute file path?

A

path from the root file system to the target file path

root starts with a /

211
Q

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

A

fs (file system)

212
Q

What method is available in the Node.js fs module for writing data to a file?

A

writeFile

213
Q

Are file operations using the fs module synchronous or asynchronous?

A

both!

214
Q

What is NPM?

A

npm is the world’s largest software registry.
npm consists of three distinct components:

the website
the Command Line Interface (CLI)
the registry

215
Q

What is a package?

A

reusable code + package.json file

directory w/ one of more files that also includes a package.json file

216
Q

How can you create a package.json with npm?

A

npm init (can include –yes at end if you dont want survey; want default package.json)

217
Q

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

A

a package your project relies on in order to function properly
third party code or your code in another file etc. that your application requires in order to function

npm install command

218
Q

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

A

downloads package from npm registry and puts into node_modules directory
dependencies property of package json is added

node_modules directory is installed

219
Q

How do you add express to your package dependencies?

A

npm install express

220
Q

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

A

listen()

221
Q

How do you mount a middleware with an Express application?

A

app.use( )

what is used to tell express what to do when you receive request or response

222
Q

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

A

request obj: data model of http request message (FROM the client)
response obj: data model of the http response message (TO the client)

next

223
Q

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

A

returns a middleware that takes in request bodies in json format and parses it and puts in on request body as an obj

224
Q

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

A

indicates desired action

a rest api
get, post, delete, updating (put, casche)

225
Q

What are the three states a Promise can be in?

A

pending, fulfilled, rejected

226
Q

How do you handle the fulfillment of a Promise?

A

using .then()

passing the return value of promise into then

227
Q

How do you handle the rejection of a Promise?

A

using .catch()
passing rejection callback function into catch

228
Q

What is Array.prototype.filter useful for?

A

filters out specific elements from one array (that fit a certain condition) into a separate array

229
Q

What is Array.prototype.map useful for

A

when you want to change all values in an entire array
transformation of an entire array

formatting strings

230
Q

What is Array.prototype.reduce useful for?

A

incrementally reduces a whole array of values into a single value

kinda like a js aggreagate function
can create an object w/ array of values
can get array of values and create a lookup obj

231
Q

What is “syntactic sugar”?

A

syntax within a programming language that is designed to make things easier to read or to express. It makes the language “sweeter” for human use
Syntactic sugar is usually a shorthand for a common operation that could also be expressed in an alternate, more verbose, form

232
Q

What is the typeof an ES6 class?

A

function! not an object

233
Q

Describe ES6 class syntax.

A

classkeyword nameofclass {

constructor(parameters) {
code block;
this.smt = “smt”;
}

prototypemethodname (parameters) {
code block;
}
etc.

}

*constructor is optional

234
Q

What is “refactoring”?

A

the process of restructuring existing computer code—changing the factoring—without changing its external behavior.
Refactoring is intended to improve the design, structure, and/or implementation of the software (its non-functional attributes), while preserving its functionality.

changing code structure w/o changing behavior

235
Q

class {}

A

the {} is the class body!

236
Q

class constructor method

A

is what runs when you use “new” to create object!!

only necessary when you want to assign properties during object initialization
when you want to use “this”?

237
Q

What is Webpack?

A

static module bundler for modern JavaScript applications.

webpack is a module bundler:
many modules ==> one module that can be loaded in the browser(usually main.js?)

*used for frontend dev?

238
Q

How do you add a devDependency to a package?

A

npm install –save-dev packagenames
npm i -D packagenames

*need the –save-dev or -D

dev dependencies help devs write/deliver the code but are not required to run the code (in production)
need during development time!!

239
Q

What is an NPM script?

A

property in package.json where the property name is any name you want, and value is a command line command

a convenient way to bundle common shell commands for your project.
They are typically commands, or a string of commands, which would normally be entered at the command line in order to do something with your application.

240
Q

How do you execute Webpack with npm run?

A

npm run propetynamewherewebpackisavalue

for webpack-intro exercise, it would be npm run build

241
Q

How are ES Modules different from CommonJS modules?

A

es: standardized module system for JS, import/export syntax

commonJS; default for node.js, require/module.export syntax

242
Q

What kind of modules can Webpack support?

A

ECMAScript, commonJS, AMD

243
Q

“default” in ES Modules

A

can only be used once per module

export default ‘myValue’

dont need curly braces

244
Q

named exports

A

many per module

grouped variables in curly braces
(like this)
export {
noop,
toArray,
createElement
}

exported declarations
like functions, variables, classes

export const foo = ‘bar’
export function myFunction() {}
export class Student {}

*imported by their exact declared name and curly braces are mandatory

245
Q

node module resolution

A

if you put a directory as file name for export or import, node.js system will automatically look for a index file to look into

es6-modules exercise: import { createElement, noop } from ‘../lib
same as import { createElement, noop } from ‘../lib/index

246
Q

inheritance extends and super in classes

A

need to use super() in constructor function to state parent class’s constructor
so watever was in parent class constructor function, you state in super() before adding more things to “this”

think to person and instructor example

247
Q

What does express.static() return?

A

a function that serves static files

248
Q

What is the local __dirname variable in a Node.js module?

A

tells us the absolute path of the current module’s directory

249
Q

What does the join() method of Node’s path module do?

A

joins all given path segments together using the platform-specific separator(/ or ) as a delimiter, then normalizes the resulting path.

250
Q

What does fetch() return?

A

a promise that will be fulfilled once response is avaliable

Then the promise resolves to the Response object representing the response to your request.

251
Q

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

A

get

252
Q

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

A

fetch (‘url’, {method: writethemethod});

second argument for fetch() is where you specify

253
Q

response.json()

A

the result is not JSON!!!
parses JSON into a JS object!

254
Q

When does React call a component’s componentDidMount method?

A

after the first successful render (lifecycle diagram shows this)

255
Q

Name three React.Component lifecycle methods.

A

componentDIdMount, componentDidUpdate, componentWillUnmount, constructor, render

256
Q

How do you pass data to a child component?

A

through props

257
Q

for asynchronous errors in express

A

need to catch w/ next(err)

258
Q

What does the acronym LIFO mean?

(data structures stacks)

A

last in, first out

259
Q

What methods are available on a Stack data structure?

A

pop(), push(value) (most important)

peek(),

print() (for debugging purposes)

260
Q

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

A

pop() each value off of stack one by one until you reach the point you want to reach

261
Q

What does the acronym FIFO mean?

data structures (queue)

A

first in, first out

262
Q

What methods are available on a Queue data structure?

A

dequeue, enqueue

263
Q

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

A

dequeue values until the pt u want to access is at the front

264
Q

How are linked lists different from an array?

A

arrays: random access (in order to go to a specific place in the list, you DONT have to start at the beginning, then jump from node to node until you get there)

linked lists: sequential access (in order to go to a specific place in the list, you have to start at the beginning, then jump from node to node until you get there), doesn’t need to be mutated to scan its contents

265
Q

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

A

traverse the list (start at head and use next property until to get to where you want)

266
Q

linked lists

A

way of organizing list of data (not the most convenient)

why they exist: due to a problem low level programmers have to deal with?

267
Q

What must the return value of myFunction be if the following expression is possible?

myFunction( ) ( );

A

a function
myFunction get called, returns a function which gets called with second parentheses

268
Q

What does this code do?

const wrap = value => ( ) => value;

A

function wrap(value) {
return function ( ) {
return value;
}
}

this is what is happening above (arrow function that returns another arrow function)

269
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

when it is defined (called lexical scope; ‘where it was written’)

270
Q

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

A