JavaScript Flashcards

1
Q

What is the purpose of variables?

A

to store data/information

without variables, we wouldn’t know what information would pertain to what

see data that come together from the past
and preserve data 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

var variable;

var is the “variable keyword”
and “variable” is the variable 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

variable name = value (number boolean string null undefined);

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

capitals and lower cases of the same letter are completely different

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

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

hold numerical values we use it for math, predominately

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 compare values with true or false

booleans are for 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

The equals sign (=) is an assignment operator. It is how you

assign a value to the variable. The assignment operator makes it so variables will contain a value

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

variable = 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 intentionally empty

undefined means theres no value there (has not been assigned a value 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

immediate identifier

good for a reference point

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

Give five examples of JavaScript primitives.

A

number boolean string 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 data type

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

What is string concatenation?

A

appending one string to the end of another 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

addition

concatenating strings

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

The plus-equals operator ( += ) adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left.

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

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

What are object properties?

A

chunk of data attached to one of those pieces of information

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

Describe object literal notation.

A

inside curly braces properties: values, each property separated by commas

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

to store items with similar data types with a similar purpose; similar values in a list format. arrays are lists

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

Describe array literal notation.

A

[item, item, item]

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, are indexed numerically, and keep a constant count of what’s inside it

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 within the array; true count (starts its count at 1)

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

the value of the length’s property - 1

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

declaration using the word “function” (function keyword)

function name (parameter) {
                     // do something
                     return something
}
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

functionName(argument)

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

no function keyword on a function call, no function block in a function call either

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 a placeholder. and an argument is the actual data that fills those parameters when we actually use the function

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

Why are function parameters useful?

A

you are able to provide values to the function and you can put different values into the same function

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 and stops the function entirely

return statement ends the function

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

verifiy youre getting the right output

debugging mechanism

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

What is a method?

A

a function stored in a property of an object

Source: Lecture

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. functions are not

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

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(indexWhereToStart, howManyElementsToDelete)

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(element);

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. You would check if you weren’t sure with console logging

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

ex .pop() maybe we weren’t concerned with what was being deleted; only that something was deleted

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 (our trusted source)

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

Give 6 examples of comparison operators.

A

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

Source: textbook duckett pages 150 - 151

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

boolean

Answer from Textbook Page 151: “[Conditions] usually result in a value of true or false.”

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 check or evaluate if a condition is true or false; to make a decision.. should I do this or not.

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 ( condition ) { }

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

What are the three logical operators?

A

&&, ||, !

logical and, logical or, and logical not
Source: Textbook Page 157

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

Using logical operators

Source: Textbook Page 156

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

What is the purpose of a loop?

A

to keep running a block of code until the condition is no longer met

a purpose of a loop is to be a way to automate actions that need to be repeated

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

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

A

condition expression is where it ends

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

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

A

one execution of the loop block

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

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

A

before the code block executes

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

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

A

before the loop begins

very first action that happens before anything

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

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

A

before the code block

just to double check if we should be doing anything

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

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

A

after the code block gets executed

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

What does the ++ increment operator do?

A

adds 1 to the variable

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

Why do we log things to the console?

A

to check to see if everything is working

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

What is a “model”?

A

a recreation of somthing; not the real thing

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

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

A

html (core of everything; first thing you see when opening a webpage)

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

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

A

datatype

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

What is a DOM Tree?

A

layout similar to a family tree that shows relations to each other

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

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

A

getElementById

querySelector

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

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

A

querySelector() for single elements

querySelectorAll() for multiple

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

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

A

to allow the browser to find the element faster

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

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

A

dir method

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

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

A

so that the html loads first

because the browser reads the code from top to bottom

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

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

A

a) a datatype DOM string

b) DOM element object

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

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

A

a) everything in a node list b) node.list

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

What is the purpose of events and event handling?

A

user interaction

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

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

A

No. Example: .addEventListener()

Duckett has a boolean argument and MDN does not

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

What is a callback function?

A

functions passed inside another function as an argument

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

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

A

event object (object built by JavaScript engine that relays al the information of the event)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
83
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 read-only target property of the Event interface is a reference to the object onto which the event was dispatched. It is different from Event.currentTarget when the event handler is called during the bubbling or capturing phase of the event.

Console.log

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

What is the difference between these two snippets of code?

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

A

1) is the callback function

2) is the return of the function call (got called before it could actually run)

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

What is the className property of element objects?

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

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

A

use .className

update by assign value

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

What is the textContent property of element objects?

A

update the text content of the object

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

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

A

.textContent property of the DOM object

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

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

A

No. Example: Did not make use of the event object at all

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
90
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, because then we would have to query the DOM to keep track of the number of clicks, which would be a pain

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

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

A

optimizes the process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
92
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
93
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
94
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
95
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
96
Q

What does the event.preventDefault() method do?

A

prevent whatever default behavior would happen

97
Q

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

A

the form keeps on refreshing

Source: Lecture

98
Q

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

A

the elements property

99
Q

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

A

the value property

100
Q

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

A

if it doesn’t work, then you’d have to check everything

101
Q

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

A

you can recognize the error very soon or right away

102
Q

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

A

No, because it still needs to be added to the DOM tree

103
Q

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

A

adult.appendChild(child);

104
Q

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

A

string attribute, value being assigned to the attribute

105
Q

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

A

createElement() string containing the element name assign to a variable, then configure (setAttribute()) then appendChild()

106
Q

What is the textContent property of an element object for?

A

specified elements & all node lists

107
Q

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

A

getAttribute();
&&
setAttribute();

“It is better to get/set the className of an element using Element.getAttribute and Element.setAttribute”

Source: https://developer.mozilla.org/en-US/docs/Web/API/Element/className (Under Notes Section)

108
Q

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

A

adjust the format for something; makes it easier to make a function for one element in an object and you can reuse said function

109
Q

What is the event.target?

A

element where the event was dispatched from (← Source: dom-event-delegation lecture)
element where the event started (← Source: javascript-view-swapping lecture)

110
Q

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

A

due to event bubbling; looks up ancestral chain

111
Q

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

A

event.target.tagName

112
Q

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

A

a) string containing a CSS selector

b) closest ancestor that matches that selector

113
Q

How can you remove an element from the DOM?

A

the .remove() method

114
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

By using event delegation

115
Q

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

A

the element is not visible/no longer visible

it’s still there for the computer, but not rendered in the output

116
Q

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

A

a) string containing a CSS selector

b) boolean (returns true or false)

117
Q

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

A

getAttribute();

with one argument: the string of the name of the attribute you want to receive

118
Q

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

A

Every step!

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

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

2 + 2 + 2 instead of 2 * 3

remanually query select the tag. manually write and its a whole mess

without event delegation, you would need an individual function for each tab

120
Q

What is JSON?

A

text format we can use to turn objects and arrays into strings

121
Q

What are serialization and deserialization?

A

serialization: object or array into string
deserialization: string to object or array

122
Q

Why are serialization and deserialization useful?

A

serialization: easy to transmit
deserialization: easy to access

123
Q

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

A

JSON.stringify();

124
Q

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

A

JSON.parse();

125
Q

How to you store data in localStorage?

A

localStorage.setItem(key, value);

126
Q

How to you retrieve data from localStorage?

A

localStorage.getItem(key);

127
Q

What data type can localStorage save in the browser?

A

string

128
Q

What data type can localStorage save in the browser?

A

string

129
Q

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

A

before the page loads

130
Q

What is a method?

A

function stored in a property of an object

131
Q

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

A

a method definition exists in an object literal. always has the function keyword & a code block

a method call uses dot notation with parenthesis at the end

132
Q

Describe method definition syntax (structure).

A

property: function (parameters) { }

133
Q

Describe method call syntax (structure).

A

object.method();

134
Q

How is a method different from any other function?

A

a method is within an object

135
Q

What is the defining characteristic of Object-Oriented Programming?

A

If you remember anything about OOP, it should be: objects can contain both data (as properties) and behavior (as methods).

Source: Instructions Documentation for the JavaScript Custom Methods Exercise

136
Q

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

A

abstraction, encapsulation, inheritance, and polymorphism

137
Q

What is “abstraction”?

A

like turning on a light on and off, we take a complex, complicated thing and turn it into a simple action

138
Q

What does API stand for?

A

Application Programming Interface

139
Q

What is the purpose of an API?

A

it allows apps to send information between each other

Source: https://www.okta.com/blog/2020/10/api-application-programming-interface/

140
Q

What is this in JavaScript?

A

it refers to the object you’re working with, essentially

141
Q

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

A

this is different from explicit parameters: it’s an implicit parameter, meaning that it is available in a function’s code block even though it was never included in the function’s parameter list or declared with var.

Source: https://lfz-lms.herokuapp.com/code-guides/Learning-Fuze/curriculum/javascript-this-basics

142
Q

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

A

call time

143
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

undefined

144
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

“It’s-a-me, Mario!”

145
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

this would be windows
and “this.firstName” is undefined.

so you get “It’s a-me undefined!” lol

146
Q

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

A

you don’t. There’s no way to know what the value of this is yet during a function definition

147
Q

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

A

check the object left of the dot

ex. object.method();

148
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype

149
Q

What is a prototype in JavaScript?

A

object that other objects can build off of

150
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

inheritance from prototypes

151
Q

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

A

it will look to the prototype

152
Q

What does the new operator do?

A

The new operator lets developers create an instance of a user-defined object type or of one of the built-in object types that has a constructor function.

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/new
(Source URL was the assigned reading for the javascript-constructors exercise)

153
Q

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

A

prototype

154
Q

What does the instanceof operator do?

A

The instanceof operator 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.

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof
(Source URL was the assigned reading for the javascript-constructors exercise)

155
Q

What is a “callback” function?

A

A callback function is a function passed into another function as an argument

Full Answer: A callback function is 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.

Source: https://developer.mozilla.org/en-US/docs/Glossary/Callback_function

156
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();

Accurate Syntax: setTimeout(functionCallWithoutParenthesis, howLongDelayTimeShouldBeInMilliseconds);

157
Q

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

A

setInterval();

Accurate Syntax: setInterval(functionCallWithoutParenthesis, timeInMillisecondsInbetweenEachFunctionCall);

158
Q

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

A

If [the delay parameter] is omitted, a value of 0 is used, meaning execute “immediately”, or more accurately, the next event cycle.

Source: https://developer.mozilla.org/en-US/docs/Web/API/setTimeout
(Source URL was the assigned reading for the javascript-timers exercise)

159
Q

What do setTimeout() and setInterval() return?

A

setTimeout(); returns a a positive integer value which identifies the timer created by the call to setTimeout(). This value can be passed to clearTimeout() to cancel the timeout.

Source: https://developer.mozilla.org/en-US/docs/Web/API/setTimeout

setInterval(); returns a numeric, non-zero value which identifies the timer created by the call to setInterval(); this value can be passed to clearInterval() to cancel the interval.

Source: https://developer.mozilla.org/en-US/docs/Web/API/setInterval

-

the timeout ID

Source: Lecture

160
Q

What is AJAX?

A

Ajax is a technique for loading data into part of a page without having to refresh the entire page.

Source: JavaScript & Jquery Textbook by Jon Duckett Page 368

161
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

Source: https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started

162
Q

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

A

XMLHttpRequest

163
Q

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

A

the load event

The load event is fired when an XMLHttpRequest transaction completes successfully.

Source: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/load_event

164
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

they share a prototype

Source: Lecture

165
Q

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

A

any line of code within { } (curly braces) is a code block

ex. function doSomething() {
     // code block
}

if statements, loops, functions

166
Q

What does block scope mean?

A

only visible within the code block

167
Q

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

A

block scope or local scope

var is function scope (Source: Lecture)

168
Q

What is the difference between let and const?

A

let is mutable and const is not (cannot reassign)

169
Q

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

A

Because the const is actually storing a reference to the array.

When you join something into your array you are not modifying your constant value,
but the array it points to.

(memory address source: lecture)

170
Q

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

A

if you know the value is going to change use let

if you don’t know if the value is going to change, use const

171
Q

What is the syntax for writing a template literal?

A

${variable name}

Note: ` backtick symbol

172
Q

What is “string interpolation”?

A

evaluating a string literal containing one or more placeholders.

Adding something into something else such as ${placeholders} into template literal

173
Q

What is destructuring, conceptually?

A

taking objects and arrays and converting it into a smaller object, arrays, and even variables

174
Q

What is the syntax for Object destructuring?

A

const {property name: variable name} = object name you want to destruct

(let or var also works where const is. Source: Lecture)

curly braces

175
Q

What is the syntax for Array destructuring?

A

const [variable names we want to take out ] = array name we want to destruct

(let or var also works where const is. Source: Lecture)

square brackets

176
Q

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

A

if it is happening on the left, it is destructuring

if it is happening on the right, it is creating (assigning? im)

177
Q

What is the syntax for defining an arrow function?

A

() optional => (single line implicit return)

() =>{return} –> multiple line it is explicit return

178
Q

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

A

the function can run without the return statement

“implicit returns” this line only Source: Lecture

179
Q

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

A

Where the function is defined.

180
Q

What is a CLI?

A

A command line interface process commands to a computer program in the form of lines of text.

181
Q

What is a GUI?

A

GUI stands for Graphical User Interface and it’s a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator.

182
Q

Give at least one use case for each of the commands listed in this exercise.

man

A

Definition: interface to the online manuals. (when trying to access system manual).

Answer (for Lecture): When you are looking for a description

183
Q

Give at least one use case for each of the commands listed in this exercise.

cat

A

cat –> concatenate files and print on the standard output (read tiles sequentially, writing them to standard output) use it to read files.

184
Q

Give at least one use case for each of the commands listed in this exercise.

ls

A

ls - list directory contents (want to see what files/contents are stored in the directory)

185
Q

Give at least one use case for each of the commands listed in this exercise.

pwd

A

pwd –> to print the full file name of the current directory

stands for print work directory

186
Q

Give at least one use case for each of the commands listed in this exercise.

echo

A

echo –> that outputs the strings it is being passed as arguments. (Print a status text)

187
Q

Give at least one use case for each of the commands listed in this exercise.

touch

A

touch –> used to update the access date and or modification date of a computer file or directory. (create a file within a directory)

[most people use it for creating files Source: Lecture]

188
Q

Give at least one use case for each of the commands listed in this exercise.

mkdir

A

mkdir –> used to make new directory (if they do not exist)

189
Q

Give at least one use case for each of the commands listed in this exercise.

mv

A

mv –> moves one or more files or directories from one place to another (and also can rename).

[a file’s name is also it’s location bc file name is also its full path Source: Lecture]

190
Q

Give at least one use case for each of the commands listed in this exercise.

rm

A

rm –> removes files or directories instantaneously.

this command is dangerous ! bc theres no way to undo this without git

191
Q

Give at least one use case for each of the commands listed in this exercise.

cp

A

cp –> copy files and directories

192
Q

What are the three virtues of a great programmer?

A

Laziness, impatience, hubris

/j

joke-y anti-hero tongue-in-cheek

193
Q

What is Node.js?

A

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

Node.js is powered by V8; the same JavaScript engine in the Google Chrome browser. It is free, open-source software and its source code is available on GitHub.

(Source: Node Intro Exercise Documentation)

194
Q

What can Node.js be used for?

A

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

web servers backend Source: Lecture

195
Q

What is a REPL?

A

read-eval-print loop (REPL) that takes single user inputs, executes them, and returns the result to the user.

example of a REPL: console (as in console.log)

196
Q

When was Node.js created?

A

May 27, 2009

197
Q

What back end languages have you heard of?

A
JavaScript
Java
Python
SQL (specifically for relational databases)
PHP
Ruby
Go
C++
C# (.NET)
Rust
F#
Closure
Haskell

(C++ & C# are in C-family)

Above Source Lecture

Alt Solution: C#, DJANGO, Node.js, PHP, Ruby on Rails

(Node is ~ only ~ backend Source: Lecture
Node.js is a framework; bigger than just a language)

198
Q

What is a computer process?

A

In computing, a process is the instance of a computer program that is being executed by one or many threads.

Source: https://en.wikipedia.org/wiki/Process_(computing)

process is the running instance

Source: Lecture

199
Q

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

A

About 120

Task Manager is the GUI of top Source: Lecture

200
Q

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

A

Because full stack developers need to deal with databases with clients and servers and such. So you want to make sure those processes are up and running so that they (clients and servers) can communicate with each other

Source: Lecture

201
Q

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

A

it is the global object of the node.js program and gives information

202
Q

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

A

(process) node.js program Source: Lecture

203
Q

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

A

Answer: Array

Alternate Answer: Array of strings (from our exercise Source: Lecture)

204
Q

What is a JavaScript module?

A

JavaScript module is a single .js file that makes a part of a whole application.

205
Q

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

A

exports, require, module, __filename, __dirname

206
Q

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

A

global (truly global) & process

Other Answers: Source Lecture console, Object, & undefined AbortController

Source: (As Shown in Lecture the webpage URL) https://nodejs.org/docs/latest-v14.x/api/globals.html
pls read that web page carefully! they list things that ARE not global and note that pls be careful future me ! im rooting for you im

207
Q

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

A

to make values or functions available to other modules

208
Q

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

A

through the require function

209
Q

What is the JavaScript Event Loop?

A

A simple task that looks at the stack and task queue if stack is empty it takes the first thing on the queue and push it. So that other codes can run simultaneously.

How asynocnous callbacks are called when the stack is cleared (Source: Lecture)

210
Q

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

A

Blocking is where other codes cannot be ran until the current call back has been completed. where non-blocking it can continue on to run other codes.

-

Blocking being on the call stack
Non-Blocking is something that runs off the call stack examples are web apis or timers

loops in javascript are blocking

^ Source: Lecture

211
Q

What is a directory?

A

location where you store files.

special type of file that lists other files (source: lecture)

212
Q

What is a relative file path?

A

refers to location that is relative to a current directory. a single dot represents the current directory itself. (starting from current working directory).

213
Q

What is an absolute file path?

A

full path/ complete location of the file or folder including which drive it is on. (starting from root directory).

214
Q

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

A

fs module

215
Q

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

A

writeFile() method

216
Q

Are file operations using the fs module synchronous or asynchronous?

A

They’re both.

217
Q

What is NPM?

A

an online repository for the publishing of open-source Node.js projects

Source: https://nodejs.org/en/knowledge/getting-started/npm/what-is-npm/

-

the npm consists of three parts:

the website.
the Command Line Interface (CLI)
the registry.

218
Q

What is a package?

A

A package is a file or directory that is described by a package.json file. A package must contain a package.json file in order to be published to the npm registry.

Source: https://docs.npmjs.com/about-packages-and-modules

According to video we watched: a package is reusable code that can be used by many programmers. These are known as modules.

Source Lecture: You don’t have to have code in the package

219
Q

How can you create a package.json with npm?

A

npm init –yes

220
Q

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

A

The dependencies value is used to specify any other modules that a given module (represented by the package.json) requires to work.

Source: https://stackoverflow.com/questions/10620583/what-is-dependency-in-package-json-nodejs

Alt Answer: Packages required by your application in production

npm install package-name

221
Q

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

A

it lists the dependency as one of the properties on package.json

222
Q

How do you add express to your package dependencies?

A

npm install express

223
Q

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

A

listen()

224
Q

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

A

application/json

225
Q

What is a directory?

A
226
Q

What are the three states a Promise can be in?

A

pending –> initial state, neither fullfilled nor rejected.
fulfilled –> meaning that the operation was completed successfully
rejected –> meaning that the operation failed

227
Q

How do you handle the fulfillment of a Promise?

A

by using then() method

228
Q

How do you handle the rejection of a Promise?

A

by using catch() method

229
Q

What is Array.prototype.filter useful for?

A

to get certain values from an array that we want

230
Q

What is Array.prototype.map useful for?

A

To return an array that is a result of a certain callback function (Source Lecture)

231
Q

What is Array.prototype.reduce useful for?

A

executing a user-supplied “reducer” callback function on each element of the array

Source: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce

Combining the elements of an array into a single value.

Source: https://lfz-lms.herokuapp.com/code-exercises/Learning-Fuze/curriculum/array-reduce?v=1337cc6ba24f354fdc2e8cf105a535dd368ff641

232
Q

What is “syntactic sugar”?

A

a way to design to make things easier to read and express. (example: SQL JOIN = INNER JOIN)

233
Q

What is the typeof an ES6 class?

A

function

234
Q

Describe ES6 class syntax.

A

class name{constructor(type){this.type=type} and method

235
Q

What is “refactoring”?

A

Restructuing existing computer code for better readability and reduce complexity.

236
Q

What does the acronym LIFO mean?

A

Last In First Out

237
Q

What methods are available on a Stack data structure?

A

pop() - Pops the “top” value off the stack.
push() - Pushes an item to the “top” of the stack
peek() - Returns the “top” value without modifying it

238
Q

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

A

Use .pop() until you reach the value that you need and then put the stack back to where it was