Javascript Flashcards

1
Q

What is the purpose of variables?

A

Store data/information

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

How do youdeclarea variable?

A

Start with variable keyword (const, var, or let) follow by a 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

Using the assignment operator ‘’=’

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

dollarsign ($) and underscore (_), letters and numbers

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

What does it mean to say that variable names are “case sensitive”?

A

The cases matter. “one” is not the same as “One”

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 text as values

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

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 show true or false

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

What does the=operator mean in JavaScript?

A

assign

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

assign a new value to that variable

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

What is the difference betweennullandundefined?

A

null is intentionally empty, will be updated later. undefined means a value has been declared by has no value.

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

it is much clearer which variables are being logged and in what order. Good for debugging

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, boolean, number, undefined and null

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

Process of joining together two or more strings

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

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

A

it can serve as an addition for arithmetic operators and a string operator for 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

adds values and then it re-assigns to same variable

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

What are objects used for?

A

grouping together a set of variables and functions with property values and methods; used to model real-life objects

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

What are object properties?

A

properties are variables that are part of an object; objects can store any data types

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

Describe object literal notation.

A

{}; opening and closing curly braces.

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

dot and bracket notation

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

What are arrays used for?

A

used for storing lists of data, numerically indexed

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

Describe array literal notation.

A

square brackets [ ]

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

numerically indexed from 0 while objects aren’t numerically indexed

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

What is thelengthproperty of an array?

A

it measures how long the array is; how many indexes are in an array

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

How do you calculate the last index of an array?

A

array[array.length-1]

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

What is a function in JavaScript?

A

a block of code designed to perform a particular task.

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

Describe the parts of a function call.

A

the function name and the arguments being passed inside the parenthesis

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

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

A

The function definition has the parameter and the code block { }. The call takes the arguments that are passed into the function.

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

What is the difference between a parameter and an argument?

A

Parameters are variables listed as a part of the function definition. Arguments are values passed to the function when it is invoked

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

Why are function parameters useful?

A

allows you to pass information into the function

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

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

A

returns the value of code and stops executing the code block

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

Why do we log things to the console?

A

To debug and check data

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

What is a method?

A

A method is a function which is a property of an object.

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

How is a method different from any other function?

A

Methods exist as a property on an object

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 exist as a property on an object/ methods can use items in the object.

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

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

A

Math.floor( ) method

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

How do you generate a random number?

A

Math.random( ) method

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

How do you delete an element from an array?

A

.splice ( ), .pop ( ), .shift( )

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

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

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

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; check by using the console log & MDN

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

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

A

A lot; 40ish

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

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

A

A lot; more than 30

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

Give 6 examples of comparison operators.

A
Less than ()
Greater than or equal (>=)
Loosely equal to (==) 
Strictly equal to (===)
Not loosely equal to (!=)
Not strictly equal to (!==)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

What data type do comparison expressions evaluate to?

A

boolean

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

What is the purpose of an if statement?

A

A conditional statement to check whether or not to do certain actions/ make a decision

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

Describe the syntax (structure) of an if statement.

A

a “if”keyword followed by a condition in parentheses ( ) and an opening curly brace for the code block and closing curly brace

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

What are the three logical operators?

A

&& (and / ampersand),
| | (or/ double pipe),
! (not / bang)

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

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

A

logical operators

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

What is the purpose of a loop?

A

to repeat an action/code

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

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

A

the purpose to sets the rules for the loop and tell it when to end.

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

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

A

the number of times it runs

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

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

A

before each iteration

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

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

A

before the condition/the loops start

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

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

A

1

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

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

A

end of each loop iteration

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

What does the ++ increment operator do?

A

increase the value by 1

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

Why do we log things to the console?

A

to test and to debug code

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

What is a “model”?

A

a recreation of something to be used as an example

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

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

A

the elements

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

What is a DOM Tree?

A

a recreation of the html elements on the page that can be acc

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

getElementById(), querySelector()

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

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

A

getElementByClassName()

querySelectorAll()

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

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

A

to store the location of the element and to stop searcgubg

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

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

A

the dir method of the console object

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

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

A

JS needs to load after the HTML - so the DOM can load first

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

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

A

an element selector and that selector

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

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

A

CSS selector and returns the NodeList

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

Why do we log things to the console?

A

checking functionality and check data; test code and debug

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

What is the purpose of events and event handling?

A

Events - the browser’s way of indicating when something has happened: page finished loading, button has been clicked

Event handlers- let you indicate which event you are waiting for on any particular element.

Overall - to trigger a function; make the page feel more interactive

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

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

A

. addEventListener( ) method

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

What is a callback function?

A

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.

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

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

A

the event object

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

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

A

It is a reference to the value of the object onto which the event was dispatched. Check with MDN

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

What is the difference between these two snippets of code?

  1. element.addEventListener(‘click’, handleClick)
  2. element.addEventListener(‘click’, handleClick())
A

The first one is a callback function and second one is calling the function. The second one immediately calls the function

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

What is the difference between these two snippets of code?

  1. element.addEventListener(‘click’, handleClick)
  2. element.addEventListener(‘click’, handleClick())
A

The first one is a callback function and second one is calling the function. The second one immediately calls the function

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

What is the className property of element objects?

A

The className property of the Element interface gets and sets the value of the class attribute of the specified element.

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

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

A

By using className property and selecting the CSS property

89
Q

What is the textContent property of element objects?

A

It represents the text content of the node and its descendants.
It selects and changes the text of the selected element and all its node

90
Q

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

A

textContent or innerText property

91
Q

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

A

generally useful but not always

92
Q

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

A

more complicated

93
Q

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

A

May cause more work and we can’t depend on the DOM

94
Q

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

A

focus event

95
Q

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

A

blur event

96
Q

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

A

input event

97
Q

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

A

submit event

98
Q

What does the event.preventDefault() method do?

A

to prevent the browser from automatically reloading the page (its default action should not be taken as it normally would be)

99
Q

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

A

reloads the page

100
Q

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

A

elements; The HTMLFormElement property elements returns an HTMLFormControlsCollection

101
Q

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

A

the value property (.value)

102
Q

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

A

Not knowing where to start when an error occurs

103
Q

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

A

checking and debugging code in real time

104
Q

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

A

No it doesn’t; it simply creates an element node (stored in a variable) that is ready to be inserted

105
Q

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

A

the appendChild() method

106
Q

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

A

name, value

107
Q

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

A

create the element, set the element’s text content (optional), append the element to a parent node

108
Q

What is the textContent property of an element object for?

A

represents the text content of the node and its descendants.

109
Q

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

A

The className property and setAttribute() method.

ex. var firstltem=document.getElementByld(‘one’);
firstltem. className = ‘complete ‘

110
Q

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

A

saves time and automation/ don’t have to repeat yourself. use it for different purposes

111
Q

What is the event.target?

A

The target property of the Event interface is a reference to the object onto which the event was dispatched.

The target event property returns the element that triggered the event.

The target property gets the element on which the event originally occurred

112
Q

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

A

event bubbling

113
Q

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

A

tagName property

114
Q

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

A

it takes a string selector and returns the closest ancestor of the selected element or itself

115
Q

How can you remove an element from the DOM?

A

.remove() method

116
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 the event listener to the parent node and delegate the child nodes

117
Q

What is the event.target?

A

The target property of the Event interface is a reference to the object onto which the event was dispatched.

The target event property returns the element that triggered the event.

The target property gets the element on which the event originally occurred

118
Q

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

A

it makes it invisible; the element is not displayed and is completely removed from the document flow.

119
Q

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

A

it takes a selectorString and returns a boolean value

120
Q

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

A

.getAttribute( attributeName ) method

121
Q

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

A

every line/step

122
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 event list every .tab element with multiple event listener

123
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 have to event list every individual .view container and assign it with if statements

124
Q

What is JSON?

A

JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax

125
Q

What are serialization and deserialization?

A

Serialization is the process of turning an object in memory into a stream of bytes so you can do stuff like store it on disk or send it over the network. (converting an object to a string)

Deserialization is the reverse process: turning a stream of bytes into an object in memory. (converting a string into an object)

126
Q

Why are serialization and deserialization useful?

A

network transmission, useful in transferring/storing data to a database, file or to memory

127
Q

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

A

the JSON.stringify method

128
Q

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

A

the JSON.parse method

129
Q

How to you store data in localStorage?

A

localStorage.setItem( ) method

130
Q

How to you retrieve data from localStorage?

A

localStorage.getItem( ) method

131
Q

What data type can localStorage save in the browser?

A

string values

132
Q

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

A

The beforeunload event is fired when the window, the document and its resources are about to be unloaded.

133
Q

What is a method?

A

A method is a function which is a property of an object.

There are two kind of methods: Instance Methods which are built-in tasks performed by an object instance, or Static Methods which are tasks that are called directly on an object constructor.

134
Q

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

A

method definition has a function keyword with it being defined while method call just has the method name with parentheses

135
Q

Describe method definition syntax (structure).

A

property in an object with function keyword and parameters in parenthesis with code in the code block between the curly braces

ex: var object = {
methodDefinition: function {
  }
}
136
Q

Describe method call syntax (structure).

A

dot notation to access the method in the object

ex: object.methodcall( )

137
Q

How is a method different from any other function?

A

it is a property of an object

138
Q

What is the defining characteristic of Object-Oriented Programming?

A

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

139
Q

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

A

Abstraction
Encapsulation
Inheritance
Polymorphism

140
Q

What is “abstraction”?

A

Abstraction is a way to reduce complexity and allow efficient design and implementation in complex software systems. It hides the technical complexity of systems behind simpler APIs.

advantage: Helps the user to avoid writing low level code.
Avoids code duplication and increases reusability.
Can change internal implementation of class independently without affecting the user.
Helps to increase security of an application or program as only important details are provided to the user.
141
Q

What does API stand for?

A

application programming interface

142
Q

What is the purpose of an API?

A

API is a computing interface that defines interactions between multiple software intermediaries;

It gives programmers a way to interact with the system in a simplified consistent fashion

143
Q

What is “this” in JavaScript?

A

This reference current object that you’re working on.

This is an implicit parameter of all JavaScript Functions; a keyword this is determined/defined at the call time

144
Q

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

A

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.

145
Q

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

A

call time

146
Q

What does “this” refer to in the following code snippet?

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

the character object

147
Q

Given the above character object, what is the result of the following code snippet? Why?

character.greet ( );

A

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

The greet property has a function and this.firstName is character.firstName

148
Q

Given the above character object, what is the result of the following code snippet? Why?

var hello = character.greet;
hello( );
A

Undefined.
The property “greet” of the “character” object is being assigned to the “hello” variable, but since greet is a method that includes other properties of the “character” object that is noted with “this”, it would not be picked up.

149
Q

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

A

You can’t determine until it’s being called.

150
Q

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

A

the value of this can be recognized as “the object to the left of the dot” when the function is called (as a method)

151
Q

What kind of inheritance does the JavaScript programming language use?

A

prototype-based (or prototypal) inheritance

152
Q

What is a prototype in JavaScript?

A

an object that will hold methods and properties that can be reused by other objects

153
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

by using their prototype object that contains those methods

154
Q

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

A

the prototype object; prototype chain

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

creates a new object type:

  1. Creates a blank, plain JavaScript object.
  2. Adds a property to the new object (__proto__) that links to the constructor function’s prototype object
  3. 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).
  4. Returns this if the function doesn’t return an object.
156
Q

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

A

the prototype property

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

158
Q

What is a “callback” function?

A

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.

159
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

the setTimeout( ) function

160
Q

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

A

the setInterval( ) function

161
Q

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

A

0 seconds / no delay

162
Q

What do setTimeout() and setInterval() return?

A

a positive integer value for the intervalID

163
Q

What is AJAX?

A

Ajax is a technique for loading data into part of a page without having to refresh the entire page. The data is often sent in a format called JavaScript Object Notation (or JSON).

a programming practice of building complex, dynamic webpages using a technology known as XMLHttpRequest.

MDN: Ajax allows you to update parts of the DOM of an HTML page instead 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).

164
Q

What does the AJAX acronym stand for?

A

Asynchronous JavaScript And XML

165
Q

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

A

XMLHttpRequest

166
Q

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

A

load event

167
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

it inherits the EventTarget prototype functionality which has the event listener function

168
Q

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

A

the code between curly braces

ex: if, switch conditions or for and while loops

169
Q

What does block scope mean?

A

it means its scope is not global and is attached and exists only inside the current block (local)

170
Q

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

A

block scope

171
Q

What is the difference between let and const?

A

const keyword creates block-scoped variables whose values can’t be reassigned vs let can be reassigned

172
Q

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

A

the value of the const variable can be changed but the value itself can’t be reassigned.

173
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 not, stick with const

174
Q

What is the syntax for writing a template literal?

A

${variable name/expression}

175
Q

What is “string interpolation”?

A

the ability to substitute part of the string for the values of variables or expressions. (also know as string formatting)

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.

takes values from arrays or properties from objects and set them to local variables

177
Q

What is the syntax for Object destructuring?

A
const or let {
propName,
PropName2,
PropName3
} = objectName;
178
Q

What is the syntax for Array destructuring?

A

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

179
Q

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

A

If it is happening on the left of the assignment operator, it is destructuring. If it is on the right side, it is defining.

180
Q

What is the syntax for defining an arrow function?

A

(parameter) => {code block}

181
Q

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

A

you do not need a return statement

182
Q

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

A

an arrow function captures the this value of the enclosing context instead of creating its own this context.

The value of this is defined when it is definition time, not when it’s called.

183
Q

What is Node.js?

A

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

184
Q

What can Node.js be used for?

A

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

185
Q

What is a REPL?

A

read-eval-print-loop – a simple programming environment that takes single user inputs, executes them, and returns the result to user; it is executed piecewise.

186
Q

When was Node.js created?

A

2009

187
Q

What back end languages have you heard of?

A

Python, PHP, Ruby, Java, .net/C#

188
Q

What is a computer process?

A

instance of a computer program that is being executed by one or many threads – a process is the actual execution of instructions

189
Q

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

A

about 150 process

190
Q

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

A

Full stack Web development is based on making multiple processes work together to form one application

191
Q

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

A

The process object is a global that provides information about, and control over, the current Node.js process. As a global, it is always available to Node.js applications without using require().

192
Q

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

A

console.log (process)

you just type process it since it is global and always available

193
Q

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

A

array

194
Q

What is a JavaScript module?

A

a single .js file.

195
Q

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

A

exports, require, module, __filename, __dirname

(function(exports, require, module, \_\_filename, \_\_dirname) {
// Module code actually lives in here
});
196
Q

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

A

console, process, and global

197
Q

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

A

Module exports are the instruction that tells Node.js which bits of code (functions, objects, strings, etc.) to “export” from a given file so other files are allowed to access the exported code.

198
Q

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

A

use require( ) function with the other Node.js as the argument

199
Q

What is the JavaScript Event Loop?

A

The event loop’s job is to look at the stack and look at the task queue. If the stack is empty it takes the first thing on the queue and pushes it on to the stack which effectively run it.

200
Q

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

A

Blocking assignment executes “in series” because a blocking assignment blocks execution of the next statement until it completes. – slow

Non-blocking assignment executes in parallel because it describes assignments that all occur at the same time.

201
Q

What is a directory?

A

File systems typically have directories – (also called folders) which allow the user to group files into separate collections

location where you store files.

202
Q

What is a relative file path?

A

refers to a location that is relative to a current directory. a single dot represents the current directory itself.

  • starting from current working directory.
  • usually starts with ./
203
Q

What is an absolute file path?

A

the exact path to a file from anywhere

full path/ complete location of the file or folder including which drive it is on.

  • starting from root directory
  • starts with forward slash /
204
Q

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

A

fs module

205
Q

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

A

writeFile( )

206
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

207
Q

What are the three states a Promise can be in?

A

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

208
Q

How do you handle the fulfillment of a Promise?

A

by using then( ) method

209
Q

How do you handle the rejection of a Promise?

A

by using catch( ) method

210
Q

What is Array.prototype.filter useful for?

A

filtering through an array without having to make for loops

211
Q

What is Array.prototype.map useful for?

A

when you want to perform functions on an array and use the returned array

212
Q

What is Array.prototype.reduce useful for?

A

to combine values in an array into one single value

213
Q

What does fetch() return?

A

returns a promise containing the response (a Response object)

note: fetch() allows you to make network requests similar to XMLHttpRequest (XHR)

214
Q

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

A

get

215
Q

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

A

fetch(resource [, init])

-add in the optional, init arguments as an object specifying ‘POST’ to the property, ‘method’.

216
Q

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

myFunction()();

A

call myFunction first then

*calling its return value of the function inside of myFunction

217
Q

What does this code do?

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

A
function wrap(value) => {
  return () => {
     return value
    }
 }

defines a function that returns a function
- the anonymous function is defined when the wrap is called

218
Q

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

A

when the function is defined

219
Q

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

A

closures