senior side Flashcards
What is a code block? What are some examples of a code block?
A code block is code within the curly braces
some examples would be function defenitions and if statements
What does block scope mean?
Block scope means that a variable is only available within the code block it was defined in
What is the scope of a variable declared with const or let?
Block scope
What is the difference between let and const?
let values are mutable and const variables are not
Why is it possible to .push() a new value into a const variable that points to an Array?
we are not changing the id of the array
How should you decide on which type of declaration to use?
let is anything you want to change and const remains the same and cant be changed
What is the syntax for writing template literals in ?
backticks (
)
${}
What is “string interpolation”?
String formatting: the ability to substitute part of the string for the values of variables or expressions. This feature is also called string interpolation.
inside a string we replace the value with the variable
What is destructuring, conceptually?
provides an alternative way to assign properties of an object to variables:
getting data from an object and storing in into variable
What is the syntax for Object destructuring?
const { firstName: fname, lastName: lname } = person;
What is the syntax for Array destructuring?
let [x, y, z] = getScores
variable name and the order their at is its index
How can you tell the difference between destructuring and creating Object/Array literals?
destructuing: brackets are on left hand side
creating: they are on the right
any chance you get to use destructuring then use it but dont have to use it all the time
what is the syntax for defining an arrow function
param => expression
var keyword function name = parameter => expression
let add = (x, y) => x + y;
When an arrow function’s body is left without curly braces, what changes in its functionality?
Without braces, you can only use an single-line expression in the body of the arrow function.
implicitly returns a value
How is the value of this determined within an arrow function?
//An arrow function captures the ‘this’ value of its enclosing context.//
takes value of this from the function it was defined from
What is a CLI?
Command line Interface
to receive commands from a user in the form of lines of text
This provides a means of setting parameters for the environment, invoking executables and providing information to them as to what actions they are to perform
What is 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 UIs, 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 man
to get the manual for the command we run
//
////
cat is used to read a file sequentially and print it to the standard output
concatenate files and print on the standard output
cat laziness.txt
//
ls -a -F
ls -a lists all contents in the working directory, including hidden files and directories
ls" on its own lists all files in the current directory except for hidden files. "ls *. // pwd to check and see the working directory you are on // echo "Hello World!" prints out text you can direct to new file with > // touch tag-your-it.txt touch creates the blank file // mkdir to make a directory // mv to move and rename files // rm to delte a file or directory // cp to copy a file or whole directory into a new name (-and-no-text >no-and-then-text) //
What are the three virtues of a great programmer?
laziness impatience hubris
cat command will print the file you give it after running cat name-of-file
pwd prints the working directory
cat laziness.txt impatience.txt hubris.txt > three-virtues.txt will create a new file named three-virtues.txt and store laziness, impatience and hubris
echo runs the string you give it right away
echo ‘Hello World!” > hello.txt will make a new file names hello.txt
mkdir command will make a directory
mv will change the name of a file
example: mv pokiemans pokemon
rm will delete a file or directort (BE CAREFUL)
cp will copy a file and give it another name if you would lie
example: cp no-and-then.txt and-then.txt
use the history command to check all the commands I ran previously
///
$ cat oceans.txt > continents.txt
> takes the standard output of the command on the left and redirects it to the file on the right.
///
ls -a lists all contents in the working directory, including hidden files and directories
///
mkdir
$ mkdir media
mkdir takes in a directory name as an argument, and then creates a new directory in the current working directory. Here we used mkdir to create a new directory named media/.
///
rm
$ rm waterboy.txt
rm deletes files. Here we remove the file waterboy.txt from the file system.
///
rm -r
$ rm -r comedy
rm -r deletes a directory and all of its child directories.
touch
$ touch data.txt
touch creates a new file inside the working directory. It takes in a file name as an argument, and then creates a new empty file in the current working directory. Here we used touch to create a new file named keyboard.txt inside the 2014/dec/ directory.
If the file exists, touch is used to update the modification time of the file
Use the ls command to list the contents of your current working directory. Try it again with the -a and -F options.
Use the ls command to list the contents of the lfz-staff/ directory. Try it again with the -a and -F options.
Use the pwd command to write your current working directory to a new file named i-was-here.txt like this:
pwd > i-was-here.txt
Use the echo command to print the string ‘Hello, World!’ to the terminal.
Use the echo command to write the string ‘Hello, World!’ to a new file named hello.txt like this:
echo ‘Hello, World!’ > hello.txt
Use the touch command to create a new file named tag-youre-it.txt.
Use the touch command to create a new file named boop.txt inside of the snoot/ directory (i.e. snoot/boop.txt).
Use the ls command to list the contents of the snoot/ directory.
mkdir
Use the ls command to list the contents of the lfz-staff/ directory and write the results to a new file at lfz-staff/contents.txt like this:
ls -aF lfz-staff > lfz-staff/contents.txt
main takeaway is it gets this from the parent scope
syntax of arrow function
have to be passing it as a callback function or define it in a variable
const add1 = (x,y) => { return x + y }
const result1 =add1(12,56)
Learned so far on senior side
const/let
template literals
arrow functions
destructuring
What is node.js?
Environment to run JavaScript code outside of the browser
What can Node.js be used for?
It is commonly used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.
What is a REPL?
Read-eval-printLoop
takes input ,reads input , evaluates input, prints the results
When was Node.js created?
2009
What back end languages have you heard of?
c++, c#, ruby python,PHp
node, java, python, c#, php c++
What is the process object in node.js
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(). It can also be explicitly accessed using require():
Gives information on whatever the current process running in Node.js is
gloablly accessable objec that contains info
How do you access the process object in a Node.js program?
passing in the process object as an argument
process is a variable
What is the data type of process.argv in Node.js?
Array
The process.argv property returns an array containing the command line arguments passed when the Node.js process was launched. The first element will be process.execPath. See process.argv0 if access to the original value of argv[0] is needed. The second element will be the path to the JavaScript file being executed. The remaining elements will be any additional command line arguments.
process. argv[0] process.execpath
proces. argv[1]. path to the javascript file
proces. argv[2] will be any command line arguments you type
notes to remember
every application is a process
process object gives us info about app that is running
process.argv is array
allows us to access data within array
we dont care about index 1 or 2
What is a module?
In JavaScript, a “module” is a single .js file. Node.js supports modules using a system heavily influenced by CommonJS.
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
Console
we will care most of exports and require function
module.exports
require is how we get stuff from other files
const add = (x,y) => x + y
module.exports = add
New file const add = require('./add')
console.log(‘Add result:’, add(4,5))
whatever exports is then thats what require is going to return
bunch of ways to export multipe things
module.exports = {
add:add
subtract: subtract
divide: divide
multiply: multiply
}
ops. add
module. exports starts as an empty object
exports. add = add
exports. subtract = subtract
can not reassign exports
What is the purpose of module.exports in a Node.js module?
The purpose is to export data to use in another file
How do you import functionality into a Node.js module from another Node.js module?
use the require function and pass in the relative path of the file
parseInt does not include decimal coverts string to number
What is the JavaScript Event Loop?
the event loops job is to look at the stack and if it is empty it takes first thing in que and runs it
responsible for executing the code, collecting and processing events, and executing queued sub-tasks.
its the process of the call stack being emptied and then runs whats in the stack and pops it and repeats
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking is any code that prevents anything else from happening
non-blocking code is something that is taking a long time we kinda push it over to the side so everything else can render
What is a directory?
A directory is a folder that contains files
What is a relative file path?
A path that links to something withi the same directory
What is an absolute file path?
a path that lead all the way to the root of the file
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 method
Are file operations using the fs module synchronous or asynchronous?
asynchronous
if you have a number to a string then you dont need to stringify
it will all become a string
JSON.stringify(data,null,2)
FINAL PROJECT
create doc
name doc
put heading on top and share
follow instructions
create figma
rename it
share file with scott and give access
create account
name it database postgres
share with scott
PLANNING come up with idea CRUD create read update delete !!!!do not use third party API!!!
START USING CSS LIBRARIES
bootstrap has most utility classes
dsiplay position’
margin padding
BEST To do it about something we like
CAR WASH PAGE
WORKOUT PAGE
What is a client?
client is a piece of computer hardware or software that accesses a service made available by a server as part of the client-server model of computer networks
the one who is making the request
Program that makes request o another computer or program
What is a server?
a server is a piece of computer hardware or software (computer program) that provides functionality for other programs or devices, called “clients”.
A programm that listens to incoming response or request
Which HTTP method does a browser issue to a web server when you visit a URL?
GET Request
What is on the first line of an HTTP request message?
An HTTP method, a verb (like GET, PUT or POST) or a noun (like HEAD or OPTIONS), that describes the action to be performed. For example, GET indicates that a resource should be fetched or POST means that data is pushed to the server (creating or modifying a resource, or generating a temporary document to send back).
The request target, usually a URL, or the absolute path of the protocol, port, and domain are usually characterized by the request context. The format of this request target varies between different HTTP methods. It can be
The HTTP version, which defines the structure of the remaining message, acting as an indicator of the expected version to use for the response.
What is on the first line of an HTTP response message?
The protocol version, usually HTTP/1.1.
A status code, indicating success or failure of the request. Common status codes are 200, 404, or 302
A status text. A brief, purely informational, textual description of the status code to help a human understand the HTTP message.
What are HTTP headers?
HTTP headers are information about the request being made
connection: common value of keep alive
Is a body required for a valid HTTP message?
no
204 no content is when none send body
What is NPM?
Node package manager
npm is the world’s largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.
npm consists of three distinct components:
the website
the Command Line Interface (CLI)
the registry
Package manager for javascript
What is a package?
collection of files that put together make up a single program or unit
How can you create a package.json with npm?
be in root of your directory and run
npm init –y’
What is a dependency and how to you add one to a package?
Dependery is packages required to use in your code
npm install package name you want
What happens when you add a dependency to a package with npm?
it updated the json file to include the depency you just added
adds list of dependencies to your package.json
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?
listen method
if you run into a error with port then another port is listening on same part
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?
app object
EXPRESS
Bind application-level middleware to an instance of the app object by using the app.use() and app.METHOD() functions, where METHOD is the HTTP method of the request that the middleware function handles (such as GET, PUT, or POST) in lowercase.
ERROR HANDLING MIDDLEWARE
Error-handling middleware
Error-handling middleware always takes four arguments. You must provide four arguments to identify it as an error-handling middleware function. Even if you don’t need to use the next object, you must specify it to maintain the signature. Otherwise, the next object will be interpreted as regular middleware and will fail to handle errors.
Define error-handling middleware functions in the same way as other middleware functions, except with four arguments instead of three, specifically with the signature (err, req, res, next)):
app.use((err, req, res, next) => {
console.error(err.stack)
res.status(500).send(‘Something broke!’)
})
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application JSON