JavaScript (Senior Side) Flashcards
What is a code block? What are some examples of a code block?
a structure that consists of one or more declarations and statements. I.e. function code block, conditional code block, loop code block.
What does block scope mean?
Anything within the code block can only be accessed within the code block.
What is the scope of a variable declared with const or let?
block
What is the difference between let and const?
The value of const can’t be changed through reassignment and it can’t be redeclared.
The value of let can be changed through reassignment and it can be redeclared.
Why is it possible to .push() a new value into a const variable that points to an Array?
Because if const is an arrray or an object, its properties or items can be updated or removed.
How should you decide on which type of declaration to use? (Const or let)
Consider whether or not the value of the variable will need to be changed in the future.
What is the syntax for writing a template literal?
backticks ( ` ` )
use $ { } to insert variables
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions.
When an arrow function’s body is left without curly braces, what changes in its functionality?
It can only return one expression
What is destructuring, conceptually?
a syntax that allows us to get specific properties of an object and store them in a variable
What is the syntax for Object destructuring?
const { value } = variable
What is a CLI?
Command Line Interface
What is the syntax for Array destructuring?
const [array] = variable
How can you tell the difference between destructuring and creating Object/Array literals?
the operands are reversed
What is the syntax for defining an arrow function?
(param) => {
}
How is the value of this determined within an arrow function?
It captures the value of the enclosing context instead of creating its own this context.
What are the three virtues of a great programmer?
Laziness
Impatience
Hubris
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of the web browser.
What can Node.js be used for?
1.back ends for Web applications
2.command-line programs
3.any kind of automation that developers wish to perform.
What is a REPL?
Read-Eval-Print-Loop. it is an interactive shell that processes Node. js expressions.
When was Node.js created?
May 27, 2009
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?
type out the process variable
What is the data type of process.argv in Node.js?
array
What is a JavaScript module?
a single .js file.
What 4 values are passed into a Node.js module’s local scope?
.exports
.require
__filename
__dirname
Give two examples of truly global variables in a Node.js program.
console
process
What is the purpose of module.exports in a Node.js module?
to be able to reuse values from other other modules
How do you import functionality into a Node.js module from another Node.js module?
with the require ( ) function
What 3 things does the JS Event Loop do?
1.) executes the code
2.) collects and processes events
3.) executes queued sub-tasks.
What is different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking code is synchronous
Non-blocking is asynchronous
What is a directory?
something that holds files and folders
What is a relative file path?
A path that refers to a location that is relative to a current directory.
What is an absolute file path?
a path that contains the root element and the complete directory list required to locate the file.
What module does Node.js include for manipulating the file system?
the ‘fs’ module
What method is available in the Node.js fs module for writing data to a file?
fs.writefile( )
Are file operations using the fs module synchronous or asynchronous?
asynchronous
What is NPM?
Node Package Manager
open source software registry for developers
What is a package?
a file that can be downloaded and used in a program
How can you create a package.json with npm?
npm init -y command
What is a dependency and how to you add one to a package?
A dependency is a third-party bit of software that was probably written by someone else and ideally solves a single problem for you.
it is installed with npm.install
What happens when you add a dependency to a package with npm?
it is added to the node modules directory
How do you add express to your package dependencies?
npm install express
What Express application method starts the server and binds it to a network PORT?
the listen method
What is a GUI?
Graphical User Interface
How do you mount a middleware with an Express application?
app.use ( )
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request object, response object, next object
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application / json
What is the significance of an HTTP request’s method?
they indicate the desired action to be performed for a given resource.
What does the express.json() middleware do and when would you need it?
Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option.
you need it when working with server requests and responses
What is PostgreSQL and what are some alternative relational databases?
It is an open source, relational database management system. Other examples include MySQL, SQL server, and oracle
What are (3) advantages of learning a relational database?
- You can store and use data sets that are
related to each other. - Data corruption is unlikely
- Support good guarantees about data
integrity
What is one way to see if PostgreSQL is running?
sudo service postgresql status