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
Describe array literal notation.
[item, item, item]
26
How are arrays different from "plain" objects?
arrays are ordered, are indexed numerically, and keep a constant count of what's inside it
27
What number represents the first index of an array?
0
28
What is the length property of an array?
number of values within the array; true count (starts its count at 1)
29
How do you calculate the last index of an array?
the value of the length's property - 1 | array.length - 1
30
What is a function in JavaScript?
reusable block of code
31
Describe the parts of a function definition.
declaration using the word "function" (function keyword) ``` function name (parameter) { // do something return something } ```
32
Describe the parts of a function call.
functionName(argument)
33
When comparing them side-by-side, what are the differences between a function call and a function definition?
no function keyword on a function call, no function block in a function call either
34
What is the difference between a parameter and an argument?
parameter is a placeholder. and an argument is the actual data that fills those parameters when we actually use the function
35
Why are function parameters useful?
you are able to provide values to the function and you can put different values into the same function
36
What two effects does a return statement have on the behavior of a function?
produces a value and stops the function entirely return statement ends the function
37
Why do we log things to the console?
verifiy youre getting the right output | debugging mechanism
38
What is a method?
a function stored in a property of an object | Source: Lecture
39
How is a method different from any other function?
methods are attached to objects. functions are not
40
How do you remove the last element from an array?
.pop()
41
How do you round a number down to the nearest integer?
Math.floor()
42
How do you generate a random number?
Math.random()
43
How do you delete an element from an array?
.splice(indexWhereToStart, howManyElementsToDelete)
44
How do you append an element to an array?
.push(element);
45
How do you break a string up into an array?
split();
46
Do string methods change the original string? How would you check if you weren't sure?
No. You would check if you weren't sure with console logging
47
Is the return value of a function or method useful in every situation?
ex .pop() maybe we weren't concerned with what was being deleted; only that something was deleted
48
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN (our trusted source)
49
Give 6 examples of comparison operators.
==, !=, >, =, <=,=== Source: textbook duckett pages 150 - 151
50
What data type do comparison expressions evaluate to?
boolean Answer from Textbook Page 151: "[Conditions] usually result in a value of true or false."
51
What is the purpose of an if statement?
to check or evaluate if a condition is true or false; to make a decision.. should I do this or not.
52
Is else required in order to use an if statement?
No
53
Describe the syntax (structure) of an if statement.
if keyword ( condition ) { }
54
What are the three logical operators?
&&, ||, ! | logical and, logical or, and logical not Source: Textbook Page 157
55
How do you compare two different expressions in the same condition?
Using logical operators Source: Textbook Page 156
56
What is the purpose of a loop?
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
57
What is the purpose of a condition expression in a loop?
condition expression is where it ends
58
What does "iteration" mean in the context of loops?
one execution of the loop block
59
When does the condition expression of a while loop get evaluated?
before the code block executes
60
When does the initialization expression of a for loop get evaluated?
before the loop begins very first action that happens before anything
61
When does the condition expression of a for loop get evaluated?
before the code block just to double check if we should be doing anything
62
When does the final expression of a for loop get evaluated?
after the code block gets executed
63
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break;
64
What does the ++ increment operator do?
adds 1 to the variable
65
How do you iterate through the keys of an object?
for..in loop
66
Why do we log things to the console?
to check to see if everything is working
67
What is a "model"?
a recreation of somthing; not the real thing
68
Which "document" is being referred to in the phrase Document Object Model?
html (core of everything; first thing you see when opening a webpage)
69
What is the word "object" referring to in the phrase Document Object Model?
datatype
70
What is a DOM Tree?
layout similar to a family tree that shows relations to each other
71
Give two examples of document methods that retrieve a single element from the DOM.
getElementById | querySelector
72
Give two examples of document methods that retrieve a single element from the DOM.
querySelector() for single elements | querySelectorAll() for multiple
73
Why might you want to assign the return value of a DOM query to a variable?
to allow the browser to find the element faster
74
What console method allows you to inspect the properties of a DOM element object?
dir method
75
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
so that the html loads first | because the browser reads the code from top to bottom
76
What does document.querySelector() take as its argument and what does it return?
a) a datatype DOM string | b) DOM element object
77
What does document.querySelectorAll() take as its argument and what does it return?
a) everything in a node list b) node.list
78
What is the purpose of events and event handling?
user interaction
79
Are all possible parameters required to use a JavaScript method or function?
No. Example: .addEventListener() Duckett has a boolean argument and MDN does not
80
What method of element objects lets you set up a function to be called when a specific type of event occurs?
.addEventListener()
81
What is a callback function?
functions passed inside another function as an argument
82
What object is passed into an event listener callback when the event fires?
event object (object built by JavaScript engine that relays al the information of the event)
83
What is the event.target? If you weren't sure, how would you check? Where could you get more information about it?
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
84
What is the difference between these two snippets of code? element. addEventListener('click', handleClick) element. addEventListener('click', handleClick())
1) is the callback function | 2) is the return of the function call (got called before it could actually run)
85
What is the className property of element objects?
86
How do you update the CSS class attribute of an element using JavaScript?
use .className | update by assign value
87
What is the textContent property of element objects?
update the text content of the object
88
How do you update the text within an element using JavaScript?
.textContent property of the DOM object
89
Is the event parameter of an event listener callback always useful?
No. Example: Did not make use of the event object at all
90
Would this assignment be simpler or more complicated if we didn't use a variable to keep track of the number of clicks?
More complicated, because then we would have to query the DOM to keep track of the number of clicks, which would be a pain
91
Why is storing information about a program in variables better than only storing it in the DOM?
optimizes the process
92
What event is fired when a user places their cursor in a form control?
focus
93
What event is fired when a user's cursor leaves a form control?
blur
94
What event is fired as a user changes the value of a form control?
input
95
What event is fired when a user clicks the "submit" button within a form?
submit
96
What does the event.preventDefault() method do?
prevent whatever default behavior would happen
97
What does submitting a form without event.preventDefault() do?
the form keeps on refreshing | Source: Lecture
98
What property of a form element object contains all of the form's controls.
the elements property
99
What property of a form control object gets and sets its value?
the value property
100
What is one risk of writing a lot of code without checking to see if it works so far?
if it doesn't work, then you'd have to check everything
101
What is an advantage of having your console open when writing a JavaScript program?
you can recognize the error very soon or right away
102
Does the document.createElement() method insert a new element into the page?
No, because it still needs to be added to the DOM tree
103
How do you add an element as a child to another element?
adult.appendChild(child);
104
What do you pass as the arguments to the element.setAttribute() method?
string attribute, value being assigned to the attribute
105
What steps do you need to take in order to insert a new element into the page?
createElement() string containing the element name assign to a variable, then configure (setAttribute()) then appendChild()
106
What is the textContent property of an element object for?
specified elements & all node lists
107
Name two ways to set the class attribute of a DOM element.
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
What are two advantages of defining a function to do create something (like the work of creating a DOM tree)?
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
What is the event.target?
element where the event was dispatched from (← Source: dom-event-delegation lecture) element where the event started (← Source: javascript-view-swapping lecture)
110
Why is it possible to listen for events on one element that actually happen its descendent elements?
due to event bubbling; looks up ancestral chain
111
What DOM element property tells you what type of element it is?
event.target.tagName
112
What does the element.closest() method take as its argument and what does it return?
a) string containing a CSS selector | b) closest ancestor that matches that selector
113
How can you remove an element from the DOM?
the .remove() method
114
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?
By using event delegation
115
What is the affect of setting an element to display: none?
the element is not visible/no longer visible | it's still there for the computer, but not rendered in the output
116
What does the element.matches() method take as an argument and what does it return?
a) string containing a CSS selector | b) boolean (returns true or false)
117
How can you retrieve the value of an element's attribute?
getAttribute(); with one argument: the string of the name of the attribute you want to receive
118
At what steps of the solution would it be helpful to log things to the console?
Every step!
119
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?
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
What is JSON?
text format we can use to turn objects and arrays into strings
121
What are serialization and deserialization?
serialization: object or array into string deserialization: string to object or array
122
Why are serialization and deserialization useful?
serialization: easy to transmit deserialization: easy to access
123
How do you serialize a data structure into a JSON string using JavaScript?
JSON.stringify();
124
How do you deserialize a JSON string into a data structure using JavaScript?
JSON.parse();
125
How to you store data in localStorage?
localStorage.setItem(key, value);
126
How to you retrieve data from localStorage?
localStorage.getItem(key);
127
What data type can localStorage save in the browser?
string
128
What data type can localStorage save in the browser?
string
129
When does the 'beforeunload' event fire on the window object?
before the page loads
130
What is a method?
function stored in a property of an object
131
How can you tell the difference between a method definition and a method call?
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
Describe method definition syntax (structure).
property: function (parameters) { }
133
Describe method call syntax (structure).
object.method();
134
How is a method different from any other function?
a method is within an object
135
What is the defining characteristic of Object-Oriented Programming?
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
What are the four "principles" of Object-Oriented Programming?
abstraction, encapsulation, inheritance, and polymorphism
137
What is "abstraction"?
like turning on a light on and off, we take a complex, complicated thing and turn it into a simple action
138
What does API stand for?
Application Programming Interface
139
What is the purpose of an API?
it allows apps to send information between each other | Source: https://www.okta.com/blog/2020/10/api-application-programming-interface/
140
What is this in JavaScript?
it refers to the object you're working with, essentially
141
What does it mean to say that this is an "implicit parameter"?
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
When is the value of this determined in a function; call time or definition time?
call time
143
``` 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); } }; ```
undefined
144
``` 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();
"It's-a-me, Mario!"
145
``` 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(); ```
this would be windows and "this.firstName" is undefined. so you get "It's a-me undefined!" lol
146
How can you tell what the value of this will be for a particular function or method definition?
you don't. There's no way to know what the value of this is yet during a function definition
147
How can you tell what the value of this is for a particular function or method call?
check the object left of the dot ex. object.method();
148
What kind of inheritance does the JavaScript programming language use?
prototype
149
What is a prototype in JavaScript?
object that other objects can build off of
150
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?
inheritance from prototypes
151
If an object does not have it's own property or method by a given key, where does JavaScript look for it?
it will look to the prototype
152
What does the new operator do?
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
What property of JavaScript functions can store shared behavior for instances created with new?
prototype
154
What does the instanceof operator do?
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
What is a "callback" function?
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
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?
setTimeout(); Accurate Syntax: setTimeout(functionCallWithoutParenthesis, howLongDelayTimeShouldBeInMilliseconds);
157
How can you set up a function to be called repeatedly without using a loop?
setInterval(); Accurate Syntax: setInterval(functionCallWithoutParenthesis, timeInMillisecondsInbetweenEachFunctionCall);
158
What is the default time delay if you omit the delay parameter from setTimeout() or setInterval()?
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
What do setTimeout() and setInterval() return?
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
What is AJAX?
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
What does the AJAX acronym stand for?
Asynchronous JavaScript And XML Source: https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started
162
Which object is built into the browser for making HTTP requests in JavaScript?
XMLHttpRequest
163
What event is fired by XMLHttpRequest objects when they are finished loading the data from the server?
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
Bonus Question: An XMLHttpRequest object has an addEventListener() method just like DOM elements. How is it possible that they both share this functionality?
they share a prototype Source: Lecture
165
What is a code block? What are some examples of a code block?
any line of code within { } (curly braces) is a code block ``` ex. function doSomething() { // code block } ``` if statements, loops, functions
166
What does block scope mean?
only visible within the code block
167
What is the scope of a variable declared with const or let?
block scope or local scope | var is function scope (Source: Lecture)
168
What is the difference between let and const?
let is mutable and const is not (cannot reassign)
169
Why is it possible to .push() a new value into a const variable that points to an Array?
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
How should you decide on which type of declaration to use?
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
What is the syntax for writing a template literal?
`${variable name}` Note: ` backtick symbol
172
What is "string interpolation"?
evaluating a string literal containing one or more placeholders. Adding something into something else such as ${placeholders} into template literal
173
What is destructuring, conceptually?
taking objects and arrays and converting it into a smaller object, arrays, and even variables
174
What is the syntax for Object destructuring?
const {property name: variable name} = object name you want to destruct (let or var also works where const is. Source: Lecture) curly braces
175
What is the syntax for Array destructuring?
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
How can you tell the difference between destructuring and creating Object/Array literals?
if it is happening on the left, it is destructuring | if it is happening on the right, it is creating (assigning? im)
177
What is the syntax for defining an arrow function?
() optional => (single line implicit return) () =>{return} --> multiple line it is explicit return
178
When an arrow function's body is left without curly braces, what changes in its functionality?
the function can run without the return statement | "implicit returns" this line only Source: Lecture
179
How is the value of this determined within an arrow function?
Where the function is defined.
180
What is a CLI?
A command line interface process commands to a computer program in the form of lines of text.
181
What is a GUI?
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
Give at least one use case for each of the commands listed in this exercise. man
Definition: interface to the online manuals. (when trying to access system manual). Answer (for Lecture): When you are looking for a description
183
Give at least one use case for each of the commands listed in this exercise. cat
cat --> concatenate files and print on the standard output (read tiles sequentially, writing them to standard output) use it to read files.
184
Give at least one use case for each of the commands listed in this exercise. ls
ls - list directory contents (want to see what files/contents are stored in the directory)
185
Give at least one use case for each of the commands listed in this exercise. pwd
pwd --> to print the full file name of the current directory stands for print work directory
186
Give at least one use case for each of the commands listed in this exercise. echo
echo --> that outputs the strings it is being passed as arguments. (Print a status text)
187
Give at least one use case for each of the commands listed in this exercise. touch
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
Give at least one use case for each of the commands listed in this exercise. mkdir
mkdir --> used to make new directory (if they do not exist)
189
Give at least one use case for each of the commands listed in this exercise. mv
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
Give at least one use case for each of the commands listed in this exercise. rm
rm --> removes files or directories instantaneously. | this command is dangerous ! bc theres no way to undo this without git
191
Give at least one use case for each of the commands listed in this exercise. cp
cp --> copy files and directories
192
What are the three virtues of a great programmer?
Laziness, impatience, hubris /j joke-y anti-hero tongue-in-cheek
193
What is Node.js?
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
What can Node.js be used for?
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
What is a REPL?
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
When was Node.js created?
May 27, 2009
197
What back end languages have you heard of?
``` 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
What is a computer process?
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
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
About 120 | Task Manager is the GUI of top Source: Lecture
200
Why should a full stack Web developer know that computer processes exist?
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
What is the process object in a Node.js program?
it is the global object of the node.js program and gives information
202
How do you access the process object in a Node.js program?
(process) node.js program Source: Lecture
203
What is the data type of process.argv in Node.js?
Answer: Array Alternate Answer: Array of strings (from our exercise Source: Lecture)
204
What is a JavaScript module?
JavaScript module is a single .js file that makes a part of a whole application.
205
What values are passed into a Node.js module's local scope?
exports, require, module, __filename, __dirname
206
Give two examples of /truly/ global variables in a Node.js program.
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
What is the purpose of module.exports in a Node.js module?
to make values or functions available to other modules
208
How do you import functionality into a Node.js module from another Node.js module?
through the require function
209
What is the JavaScript Event Loop?
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
What is different between "blocking" and "non-blocking" with respect to how code is executed?
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
What is a directory?
location where you store files. special type of file that lists other files (source: lecture)
212
What is a relative file path?
refers to location that is relative to a current directory. a single dot represents the current directory itself. (starting from current working directory).
213
What is an absolute file path?
full path/ complete location of the file or folder including which drive it is on. (starting from root directory).
214
What module does Node.js include for manipulating the file system?
fs module
215
What method is available in the Node.js fs module for writing data to a file?
writeFile() method
216
Are file operations using the fs module synchronous or asynchronous?
They're both.
217
What is NPM?
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
What is a package?
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
How can you create a package.json with npm?
npm init --yes
220
What is a dependency and how to you add one to a package?
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
What happens when you add a dependency to a package with npm?
it lists the dependency as one of the properties on package.json
222
How do you add express to your package dependencies?
npm install express
223
What Express application method starts the server and binds it to a network PORT?
listen()
224
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
225
What is a directory?
226
What are the three states a Promise can be in?
pending --> initial state, neither fullfilled nor rejected. fulfilled --> meaning that the operation was completed successfully rejected --> meaning that the operation failed
227
How do you handle the fulfillment of a Promise?
by using then() method
228
How do you handle the rejection of a Promise?
by using catch() method
229
What is Array.prototype.filter useful for?
to get certain values from an array that we want
230
What is Array.prototype.map useful for?
To return an array that is a result of a certain callback function (Source Lecture)
231
What is Array.prototype.reduce useful for?
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
What is "syntactic sugar"?
a way to design to make things easier to read and express. (example: SQL JOIN = INNER JOIN)
233
What is the typeof an ES6 class?
function
234
Describe ES6 class syntax.
class name{constructor(type){this.type=type} and method
235
What is "refactoring"?
Restructuing existing computer code for better readability and reduce complexity.
236
What does the acronym LIFO mean?
Last In First Out
237
What methods are available on a Stack data structure?
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
What must you do to access the value at an arbitrary point in a stack (not just the "top")?’
Use .pop() until you reach the value that you need and then put the stack back to where it was