JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store data and information to be used later. keeps a history of 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

var
let
const

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

=

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

What characters are allowed in variable names?

A

letters, $, _, numbers(numbers cannot be the first character)

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

casing matters in variables

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

What is the purpose of a string?

A

to be able to give a variable a value of 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

to assign variables a numerical value

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

making decisions

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

assigns a value to something so that it will contain it

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

declare and assign it a new value

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

What is the difference between null and undefined?

A

null is an empty value purposely given while undefined means nothing is defined yet

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

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

A

specifies what the value relates to

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

Give five examples of JavaScript primitives.

A
boolean
string
number
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

appending a string to another end of a string

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

What purpose(s) does the + plus operator serve in JavaScript?

A

string concatenation and addition

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

addition assignment and the result of that will be the updated value

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

What are objects used for?

A

to store multiple types of data

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

What are object properties?

A

a piece of data stored in an object

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

Describe object literal notation.

A

data within a { and a , separating each one

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

dot notations and square brackets

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

What are arrays used for?

A

objects with similar data types in a list format

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

Describe array literal notation.

A

declare a variable
square bracket
values contained in the bracket

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

arrays are ordered, indexed numerically, constant count of what is inside

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

number of values in the array

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

reusable block of code

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
function keyword
name of function
parameter(s)
code block
return keyword
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Describe the parts of a function call.

A

( )

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

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

A
function calls does not have the keyword function
function calls have arguments and data
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is the difference between a parameter and an argument?

A

parameter is the place holder which is used when defining a function
arguments replace the parameter when the function is being called

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

Why are function parameters useful?

A

so that you can provide values with arguments when the function is being called

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

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

A

produces a value from the function

it stops the code of the function from running any further

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

Why do we log things to the console?

A

verify outputs. a debugging mechanism

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

What is a method?

A

function stored in a property

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

How do you remove the last element from an array?

A

pop()

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

How do you generate a random number?

A

Math.random()

gives a number from 0-1. inclusive of 0 but not of 1.

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

How do you delete an element from an array?

A

splice()

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

How do you append an element to an array?

A

push()

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

How do you break a string up into an array?

A

split()

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

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

A

No

console.log() to check

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

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

A

No. You may be using the function or method for what it does and not necessarily the return

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

Give 6 examples of comparison operators.

A

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

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

What is the purpose of an if statement?

A

to determine which code block is to be run

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

Describe the syntax (structure) of an if statement.

A

if keyword, conditional code block
if (condition) {
code block
}

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

What are the three logical operators?

A

&& , || , !

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

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

A

&& , ||

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

Why do we log things to the console?

A

to make sure our code is correct

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

What is a “model”?

A

something that is easier to represent of a concept.

a representation of something

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

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

A

referring to javascript objects

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

What is a DOM Tree?

A

collection of html elements similar to a family tree

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

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

A

querySelectorAll
querySelector
(use these methods only)

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

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

A

querySelectorAll

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

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

A

to store the data and use it later

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

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

A

dir method

dir()

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

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

A

because it is read top to bottom. if you put the script tag above anything, it won’t be read

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

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

A

css selector as an argument in a string form.
returns one object
finds the first selector and disregards the rest

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

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

A

css selector as an argument in a string form.
returns an object
finds all selectors and produces it

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

Why do we log things to the console?

A

to check if your code works

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

What is the purpose of events and event handling?

A

is for user interaction

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

What is a callback function?

A

a function that is passed inside another function as an argument

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

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

A

it is the object javascript created when the event happens which is passed into the call back function

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

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

A

object referencing where ever this event started from

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

What is the difference between these two snippets of code?

element. addEventListener(‘click’, handleClick)
element. addEventListener(‘click’, handleClick())

A

first one has a callback function
second one has a function call (second one, the event will happen immediately when the page loads. event listener will not work)

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

What is the className property of element objects?

A

sets the name of a class name

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

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

A

object.className = “new class name”

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

What is the textContent property of element objects?

A

allows you to update the text of the object

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

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

A

.textContent on a dom object with an assignment operator to update the text
object.textContent = “text content”

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

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

A

its more easily accessible in a variable

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

What does the event.preventDefault() method do?

A

it stops the default behavior of something
example: putting event.preventDefault() within a function in an event listener with submit buttons will make sure the page does not refresh when you click submit

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

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

A

it will refresh the page

89
Q

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

A

.elements

90
Q

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

A

.value

91
Q

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

A

it might not work

and you don’t know what is not working

92
Q

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

A

to see if things are working or aren’t working

93
Q

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

A

no because it has not been added visible portion yet

94
Q

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

A

parent.appendChild(child)

95
Q

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

A

the string of the name of the attribute

second is the string of the value of the attribute

96
Q

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

A

called the createElement method and assign it to a variable

appendChild this new element by passing the variable as the argument

97
Q

What is the textContent property of an element object for?

A

set the text content of a specific element

98
Q

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

A

setAttribute and className

99
Q

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

A

you do not have to write the code over again when you have a function
you can make it loop

100
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 the function multiple times instead of just one use

101
Q

What is the event.target?

A

the element where the event started from

102
Q

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

A

event bubbling

103
Q

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

A

tagname property

104
Q

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

A

css selector format as a string

return is a closest ancestor that matches that selector

105
Q

How can you remove an element from the DOM?

A

remove method

remove()

106
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

event delegation

107
Q

What is the event.target?

A

element where the event started

108
Q

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

A

the element cannot be seen or interacted with

109
Q

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

A

the argument is the name of the element as a string in css format
the return a true or false statement (boolean)

110
Q

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

A

element.getAttribute()

111
Q

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

A

every step

112
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 have to write another function in javascript for this tab

113
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

you would need another function to show and hide each page

114
Q

What is a breakpoint in responsive Web design?

A

Its the point where the styling changes

115
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

a percentage width will be responsive and adaptive to the viewport

116
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

Source order lets the smaller min-width take priority

117
Q

What is JSON?

A

javascript object notation
text format of an object
this will be in a string data type

118
Q

What are serialization and deserialization?

A

serialization - object into string

deserialization - string into object

119
Q

Why are serialization and deserialization useful?

A

its useful transferring data

120
Q

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

A

JSON.stringify()

121
Q

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

A

JSON.parse()

122
Q

How to you store data in localStorage?

A

localStorage.setItem()

123
Q

How to you retrieve data from localStorage?

A

localStorage.getItem()

124
Q

What data type can localStorage save in the browser?

A

strings

125
Q

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

A

before you leave the page

126
Q

What is a method?

A

a function stored in the property of an object

127
Q

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

A

method definition is in the property value. has a function keyword, and a code block
method call is used with dot notation and has a parenthesis
object.method()

128
Q

Describe method definition syntax (structure).

A

function keyword, parameters, and a colon for assigning it to a property, property name

129
Q

Describe method call syntax (structure).

A

object.method()

130
Q

How is a method different from any other function?

A

methods are within an object

131
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

132
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

133
Q

What is “abstraction”?

A

being able to work with (possibly) complex things in simple ways
You usually flip a light switch on or off to control the light in a room. The reality is that you are closing an electrical circuit that connects to a mains breaker somewhere in your home so that 120 volts at 15 amps goes through a light bulb. But to you, you are “turning on the lights”.

134
Q

What does API stand for?

A

Application Programming Interface

a set of tools someone created to let you interact with

135
Q

What is the purpose of an API?

A

communications between multiple software

136
Q

What is this in JavaScript?

A

The object you are working with

137
Q

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

A

an implicit parameter is not named

138
Q

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

A

call time

139
Q

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

A

it is impossible to find out what is this if the function is only being defined

140
Q

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

A

just the object to the left of the dot

141
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance

142
Q

What is a prototype in JavaScript?

A

a JavaScript prototype is simply an object that contains properties and (predominantly) methods that can be used by other objects.

143
Q

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

A

prototypes

144
Q

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

A

to its prototype

145
Q

What does the new operator do?

A

Creates a blank, plain JavaScript object.
Adds a property to the new object (__proto__) that links to the constructor function’s prototype object
Binds the newly created object instance as the this context (i.e. all references to this in the constructor function now refer to the object created in the first step).
Returns this if the function doesn’t return an object.

146
Q

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

A

prototype property

147
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. The return value is a boolean value.

148
Q

What is a “callback” function?

A

function passed into another function as an argument or value

149
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

setTime()

150
Q

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

A

setInterval()

151
Q

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

A

0

152
Q

What do setTimeout() and setInterval() return?

A

time out id

153
Q

What is AJAX?

A

a group of technologies that offer asynchronous functionality in the browser
application designed to retrieve data and put it on a portion of a webpage without refreshing the whole page

154
Q

What does the AJAX acronym stand for?

A

it stood for Asynchronous Javascript and XML, but the technologies have moved on, but the term Ajax is still used

155
Q

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

A

XMLHttpRequests

156
Q

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

A

“load”

157
Q

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

A

because it is an object that supports events

158
Q

What is the purpose of a loop?

A

to keep executing a block of code until the condition is false

159
Q

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

A

when a loop will end

160
Q

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

A

one loop

161
Q

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

A

before the code block is executed

162
Q

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

A

before the loop begins

163
Q

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

A

evaluated before the code block is run every time

164
Q

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

A

right after each code block is executed

165
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

166
Q

What does the ++ increment operator do?

A

increment a value by 1

167
Q

How do you iterate through the keys of an object?

A

for in loop

168
Q

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

A

code within {}

169
Q

What does block scope mean?

A

relevant to that specific code block. it is no longer accessible outside of that scope

170
Q

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

A

blocked scoped

171
Q

What is the difference between let and const?

A

the variable of const cannot be reassigned using the assignment operator. it can be changed and mutated, but not reassigned

172
Q

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

A

because const is storing the reference of the array. you can still change the array but you cannot reassign const using the assignment operator again

173
Q

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

A

if the variable is going to be reassigned, use let

if the variable is going to stay const, use const

174
Q

What is the syntax for writing a template literal?

A

`` for strings

${ } for variables

175
Q

What is “string interpolation”?

A

The JavaScript engine will automatically replace these variables and expressions with their values when using template literals. This feature is known as string interpolation.

176
Q

What is destructuring, conceptually?

A

The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
taking objects and arrays and converting it into a smaller object, arrays, and even variables

177
Q

What is the syntax for Object destructuring?

A

var {name of property} = object

178
Q

What is the syntax for Array destructuring?

A

var [name of property] = array

179
Q

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

A

object and array literals have their brackets on the right side
if the brackets are on the left side, it is destructuring

180
Q

What is the syntax for defining an arrow function?

A

parameter and the arrow symbol

parenthesis is required only if there are no parameters or more than one

181
Q

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

A

if there is a curly brace, you need to have a return statement.
if there is no curly brace, the return statement is implied

182
Q

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

A

where the function is defined

183
Q

What is a CLI?

A

command-line interface

184
Q

What is a GUI?

A

graphical user interface

185
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 - used to view the manuals of a command
cat - used to concatenate files and print on the standard output
ls - list directory contents
pwd- print name of current/working directory
echo- display a line of text
touch- change file timestamps
mkdir- make directories
mv- move (rename) files
rm- remove files or directories
cp- copy files and directories

186
Q

What are the three virtues of a great programmer?

A
  1. Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don’t have to answer so many questions about it.
  2. Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to.
  3. Hubris: The quality that makes you write (and maintain) programs that other people won’t want to say bad things about.
187
Q

What is the JavaScript Event Loop?

A

it is a function within the browser that pushes events that were previously delayed (such as setTimeout or SetInterval) into action by pushing it into the “stack”. It only pushes it into the “stack” the “stack” is empty.
it is how asynchronous callbacks are called when the stack is clear

188
Q

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

A

if something is “blocking” the event loop cannot occur as code still needs to be executed before it is unblocked

189
Q

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

A

if something is “blocking” (something is in the stack) the event loop cannot occur as code still needs to be executed before it is unblocked

190
Q

What is a directory?

A

a directory is a way of organizing data. directories contain other files and possibly other directories

191
Q

What is a relative file path?

A

a file path starting from the current directory

192
Q

What is an absolute file path?

A

it is a file path to any file anywhere in the system starting from the root

193
Q

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

A

fs

194
Q

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

A

writeFile()

195
Q

Are file operations using the fs module synchronous or asynchronous?

A

depending on the method, they are ether synchronous or asynchronous

196
Q

What is NPM?

A

makes it easier for javascript developers to share the code they have created to solve particular problems
stands for node package manager

npm consists of three distinct components:
the website
the Command Line Interface (CLI)
the registry

197
Q

What is a package?

A

a package is a directory with one or more files in it.

in terms of NPM, the package will include package.json that will include some meta data

198
Q

How can you create a package.json with npm?

A

npm init –yes

199
Q

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

A

a package you download to run your program. the package should generally have code to implement in your own code
npm install jquery

200
Q

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

A

will add a node_modules folder and add the package into there. it will also update the dependencies property of package.json

201
Q

What are the three states a Promise can be in?

A

pending
fulfilled
rejected

202
Q

How do you handle the fulfillment of a Promise?

A

using .then()

the first argument of a then() should be the function that handles the fulfillment

203
Q

How do you handle the rejection of a Promise?

A

using .then() or .catch()

the second argument of then() should be the function that handles the rejection

204
Q

What is Array.prototype.filter useful for?

A

useful for filtering out elements in arrays to a new array

205
Q

What is Array.prototype.map useful for?

A

Creating a new array containing the transformed elements of another.

206
Q

What is Array.prototype.reduce useful for?

A

combined everything into one value.

output is an array

207
Q

What is “syntactic sugar”?

A

a style of code used to make it easier to read and write

208
Q

What is the typeof an ES6 class?

A

function

209
Q

Describe ES6 class syntax

A
class Person {
    constructor(name) {
        this.name = name;
    }
    getName() {
        return this.name;
    }
}
constructor method is optional.
210
Q

What is “refactoring”?

A

the process of restructuring to make code better but the functionality is the same

211
Q

How are ES Modules different from CommonJS modules?

A

ES Modules are static and have to go to the top of the file (will be using this for front-end in class)
CommonJS is dynamic and do not have to be at the top of the file (will be using this for back-end in class)

211
Q

What kind of modules can Webpack support?

A

ECMA script modules, CommonJS modules, AMD, web assembly

212
Q

What does fetch() return?

A

returns a promise to resolve the response object

213
Q

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

A

GET

214
Q

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

A

by passing it an object as another argument in fetch() and have a property key method, followed by which ever request method you want in a string form

{
method: “GET”
}

215
Q

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

A

the return of the inner function

216
Q
What does this code do?
const wrap = value => () => value;
A
const wrap = function (value) {
return function (){
return value
}

the variable wrap is holding the function definition. if wrap is called with an argument, it returns a second function with no parameters. If the second function is called, it returns the first argument.

217
Q

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

A

when its defined

218
Q

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

A

closures