Week 8 and Week 9 Quiz Questions Flashcards
What is a code block? What are some examples of a code block?
lines of code used in and denoted by curly braces {} often used in if statements, for loops, do while loops, etc
What does block scope mean?
in block scope, variables and other items/ objects are only referenced within the block itself, and thus have no effect on the global scale or other codes blocks in a function.
What is the scope of a variable declared with const or let?
both are block level
What is the difference between let and const?
const is immutable and cannot be changed– it is read-only.
Why is it possible to .push() a new value into a const variable that points to an Array?
values of const variables can change, but the const variable cannot directly be edited(array is referenced datatype and not a primitive (that cannot be changed))
How should you decide on which type of declaration to use?
look at scope first, then think about if variables can just be read-only and never changed vs if variable can/ needs to be changed
What is the syntax for writing a template literal?
use backticks (`) instead of quotation
variables called by using ${variableName} inside backticks
What is “string interpolation”?
substituting part of a string for the value of a variable or expression
What is destructuring, conceptually?
being able to assign component parts of arrays and objects into variables
What is the syntax for Object destructuring?
const {variable1, variable2} = object;
OR
const {prop1: variable1, prop2: variable2} = object;
What is the syntax for Array destructuring?
const [variable1, variable2] = array;
How can you tell the difference between destructuring and creating Object/Array literals?
brackets come first before equals sign
What is the syntax for defining an arrow function?
const variableName = (parameter1, parameter2) => {function code block}
When an arrow function’s body is left without curly braces, what changes in its functionality?
return is implied. only one expression (line) is read as well
How is the value of this determined within an arrow function?
this is defined at definition time not call time in arrow functions.
this in arrow functions
this in arrow functions reference the relative object they are in. (as opposed to this being the window object) DIRECT PARENT
What is a CLI?
`
command line interfaces
What is a GUI?
graphical user interface
What are the 3 components of a fullstack Web architecture?
The frontend that the user interacts with (Web site or Mobile app)
The backend server that takes requests from the frontend and processes them
The database where data is stored and used across all instances of the frontend
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of a web browser.
What can Node.js be used for?
It is commonly used to build backends for Web applications, command-line programs, or any kind of automation that developers wish to perform.
What is a REPL?
read-evaluate-print loop
When was Node.js created?
May 27, 2009
What backend languages have you heard of?
python, java
What is a computer process?
computer process executes the passive “instructions” from a computer program– an application that is running is a process
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
hundreds
Why should a full stack Web developer know that computer processes exist?
to understand how their programs actually interact with a computer
What is the process object in a Node.js program?
a global that provides information about, and control over, the current Node.js process
How do you access the process object in a Node.js program?
can just log it? – can just type in ‘process’
What is the data type of process.argv in Node.js?
array
How do you access the command line arguments in a Node.js program?
process.argv[index]
What is a JavaScript module?
In JavaScript, a “module” is a single .js file.
What are the advantages of modular programming?
easy to change/ edit individual modules/ functions
In JavaScript, how do you make a function in a module available to other modules?
use:
export { function as default }
In JavaScript, how do you use a function from another module?
use:
import function from ‘./filename.ext’
What is the JavaScript Event Loop?
pushes the first item in the code task queue to the call stack (order in which code is executed) if the call stack is empty
What is different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking refers to operations that block further execution until that operation finishes while non-blocking (asynchronous) refers to code that doesn’t block execution
What are the three states a Promise can be in?
pending, fulfilled, rejected
How do you handle the fulfillment of a Promise?
.then()
How do you handle the rejection of a Promise?
.catch()
What does Array.filter do?
creates a shallow copy of Array if the elements in the array pass the test (truthy) that is in filter
What should the callback function return?
truthy/falsey or true/false (boolean)
What is Array.filter useful for?
when checking an array, if items are true/ false.
What does Array.map do?
returns new array of elements that are created from original array that is passed through a function
What should the callback function return?
a new result of the array at that index as the return of the function
What is Array.map useful for?
applying the same change to multiples items in an array
What does Array.reduce do?
Returns final result of running the reducer function across all elements of the array is a single value.
What action should the callback function perform?
contains an accumulator and currentValue (and initialValue sometimes)
accumulator accumulates the currentValues through the array until the end and returns the final result as a single value from the accumulator
What should the callback function return?
the value from accumulator
What is Array.reduce useful for?
gathering/ combining contents/ values of an array into one value
What is a directory?
collection of locations of files
What is a relative file path?
./fileName
shortest way to get the file you need relative to current location
What is an absolute file path?
points to absolute location of file regardless of your location
What module does Node.js include for manipulating the file system?
fs
What method is available in the node:fs module for reading data from a file?
readFile()
What method is available in the node:fs module for writing data to a file?
writeFile()
Are file operations using the fs module synchronous or asynchronous?
asynchronous
What is a client?
a ‘thing’ (software/ program) that requests a service