Senior Side Flashcards
What is a code block? What are some examples of a code block?
a chunk of code that will do a specific task when appropriate (when the function is called or a conditional is met/true)
Examples: if statement, for loop, while loop, etc
What does block scope mean?
the variables exist only within the corresponding block; variables are not visible outside the block
as opposed to function scoped
What is the scope of a variable declared with const or let?
block-scoped
What is the difference between let and const?
let: you can reassign them to different values, but you can’t redeclare; you don’t need to initialize it with a value
const: immutable so you can’t reassign them to different values, nor can you redeclare; requires an initializer, const key-words are read-only variables
Why is it possible to .push() a new value into a const variable that points to an Array?
the reference to the variable is immutable but the value of the variable is not so you can manipulate it
How should you decide on which type of declaration to use?
determine whether or not you will need to reassign said variable; if you will need to reassign it at some point, use let. If not, you can use const
What is the syntax for writing a template literal?
wrap the string in backticks
any expressions or variables go inside curly braces with a dollar sign before
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions
What is destructuring, conceptually?
taking properties and values from an object and assigning their values to independent variable
What is the syntax for Object destructuring?
const {names you want to assign to your variables} = object
What is the syntax for Array destructuring?
const [names you want to assign to your variables] = array
How can you tell the difference between destructuring and creating Object/Array literals?
where the brackets/curly braces are
What is the syntax for defining an arrow function?
param => expression
( ) => expression
(param1, param2, … ) => expression
When an arrow function’s body is left without curly braces, what changes in its functionality?
without curly braces, implicit return will happen
if no curly braces, the expression must be a single expression
can’t have statements (eg. return, if, for loops etc)
How is the value of this determined within an arrow function?
an arrow function captures the this value of the enclosing context instead of creating its own this context
doesn’t have its own this value
lexical scope: where you wrote it
this is defined at the call time of its outer function (lexical scope)
What is a CLI?
Command-line interface processes commands to a computer program in the form of lines of text
What is a GUI?
Graphical user interface is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, instead of text-based user interfaces, typed command labels or text navigation
Give at least one use case for each of the commands listed in this exercise. man cat ls pwd echo touch mkdir mv rm cp
man- interface to online reference manuals (use when there’s a command you don’t know much about)
cat- concatenate files and print on the standard output (use when you want to see contents of file or even combine files together in a new file)
ls- list directory contents (when you want to see what is inside the current directory)
(-a do not ignore entries that start with .
- F append indicator to entries)
pwd- print name of current/working directory ( when you want to know which directory you are in currently)
echo- display a line of text (when you want to display text and possibly put that text into a file)
touch- create new files
mkdir- make directories
(-p makes parent directories as needed)
mv- rename files/directories
rm- delete files
(-r removes directories and all their contents
-f ignore nonexistent files and arguments, never prompt)
cp- copy files and directories
(-r copy directories recursively)
What are the three virtues of a great programmer?
Laziness, Impatience, Hubris
What is Node.js?
a program that allows JavaScript to be run outside of a web browser
an asynchronous event-driven JavaScript runtime
Node.js is a set of libraries for JavaScript which allows it to be used outside of the browser
What can Node.js be used for?
used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform
It is primarily focused on creating simple, easy-to-build network clients and servers
What is a REPL?
Read-Eval-Print-Loop
an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user
An example of a repl is the inspect tools
When was Node.js created?
2009
What back-end languages have you heard of?
Python, Ruby, php, Java, C#, Perl, coldfusion, Scala, JavaScript, Go, Rust, C, C++, cobol, kotlin, clojure, crystal, elixir, erlang
.net (framework in C#)
SQL (database)
frameworks are libraries written within a language
What is a computer process?
a program or task running on your computer
program: like the code you want to run
process: like the code actually running
the instance of a computer program that is being executed by one or many threads. It contains the program code and its activity
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
665
Why should a full-stack Web developer know that computer processes exist?
front-end and back-end are two different processes
if we’re trying to send a request to the back-end and it’s not working, we need to make sure the back-end process is actually running
for a full-stack app to work we need a front-end process (Chrome), a back-end process (Node.js), and a database process (PostSQL?)
What is the process object in a Node.js program?
The process object is 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?
you can just console.log process to access the process object; since its global, it’s always available to Node.js applications
What is the data type of process.argv in Node.js?
array of strings
What is a JavaScript module?
a single .js file
What values are passed into a Node.js module’s local scope?
exports, require, module, _filename, _dirname
Give two examples of truly global variables in a Node.js program.
process, global, console, URL, clearImmediate(immediateObject), clearInterval(intervalObject), clearTimeout(timeoutObject)
What is the purpose of module.exports in a Node.js module?
allows for variables in one module to be used in another file
module exports is an empty object that allows you to put modules inside that you want to be exported and used in other files when using the require function
it gives you access to what modules are being exported
How do you import functionality into a Node.js module from another Node.js module?
using the require function when you pass in a string of the ID or the path of the module you want to import
What is the JavaScript Event Loop?
orchestrates asynchronous functions (so our callback functions)
the event loop checks the call stack and the task queue, if the call stack is empty it looks to the task queue, takes the first thing on the queue, and places it on the stack
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking is when there is code that is slow on the call stack. this becomes an issue because blocking that stack means the browser can’t do anything while it waits for everything to run
blocking methods execute synchronously
non-blocking methods execute asynchronously
if there’s a code running, no other code can be running
blocking is anything that just sits on the call stack until it is complete
non-blocking is something that is deferred to the task queue that waits to be executed
What is a directory?
a directory is a file system cataloging structure which contains references to other computer files, and possibly other directories
we call them folders on computers but folders are just icons lol
What is a relative file path?
location relative to the current directory
What is an absolute file path?
contains the root which you can see started by a forward slash, and a directory list to get where you need to be
where is this thing in the entire system
What module does Node.js include for manipulating the file system?
fs module
What method is available in the Node.js fs module for writing data to a file?
writeFile
Are file operations using the fs module synchronous or asynchronous?
asynchronous by default
if it says Sync at the end of the method then it’s synchronous
What is NPM?
the world’s largest software registry where developers can share and borrow packages
made of the website, CLI, and a registry
CLI is a way to add or get stuff from the website and the registry
What is a package?
modules, bits of reusable code, if it has a package.json, then it is considered a package
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What is on the first line of an HTTP request message?
- HTTP method (GET, POST, etc)
- The request target (usually a URL)
- HTTP version
What is on the first line of an HTTP response message?
- Protocol version
- Status code
- Status text
What are HTTP headers?
they allow the client and server to pass additional information with an HTTP request or response
Is a body required for a valid HTTP message?
no it’s optional
What is a package?
modules, bits of reusable code, if it has a package.json, then it is considered a package
directory with one or more files in it PLUS a package.json
How do you add express to your package dependencies?
npm install express
The difference between these two, is that devDependencies are modules which are only required during development, while dependencies are modules which are also required at runtime
What Express application method starts the server and binds it to a network PORT?
listen method
Binds and listens for connections on the specified host and port
How do you mount a middleware with an Express application?
use the use method of the app object