Week 8 Flashcards

1
Q

What is a code block? What are some examples of a code block?

A

A set of code within curly braces.
Examples: function code block, loop code block

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does block scope mean?

A

It means that the variable that was defined within a block will not be accessible from outside the block aka outside of the curly braces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the scope of a variable declared with const or let?

A

block scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What’s the difference between let and const?

A

Const are variables that cannot be reassigned

You also need to initialize the value declared by the const keyword (ex: cannot just say const red;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why is it possible to .push() a new value into a const variable that points to an array?

A

The value within the array is mutable
You cannot change the value of a constant through reassignment but you can update the value of the properties or items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How should you decide on which type of declaration to use?

A

If the variable is not going to be reassigned, use const
if it is going to be reassigned, use let

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the syntax for writing a template literal?

A

Wrap the text in backticks ` and include any expressions inside of the template literal with ${}
example:
const fruit = ‘apple’
const item = ‘pen’
const applepen = ${fruit}${item}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is string interpolation?

A

technique that allows you to insert variable or expression values into a strings
const fruit = ‘apple’
const item = ‘pen’
const applepen = ${fruit}${item}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the syntax for defining an arrow function?

A

( parameter1, paremeter2, etc..) => { }
if it has no parameters, parenthesis are mandatory. If there is 1 parameter, parenthesis are not mandatory. If there are multiple, it is mandatory.
If there is a simple expression, curly braces are not needed. If there are multiple statements, it requires curly braces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When an arrow function’s body is left without curly braces, what changes in its functionality?

A

Without curly braces, the arrow function has an implicit return (returns something even without the return keyword)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How is the value of this determined within an arrow function?

A

The value of this is determined by surrounding scope/surrounding code block. aka it doesn’t have its own value and will look outward. aka the value of this will be determined at definition time

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is CLI?

A

Command line interface: receives commands from a user in the form of lines of text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is GUI?

A

Graphical user interface: form of user interface that allows users to interact through graphical icons and audio indicator instead of text-based UIs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Give one use case for the command: man

A

Documentation for commands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Give one use case for the command: cat

A

concatenate files and print on the standard output

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Give one use case for the command: ls

A

lists directory content and sorts alphabetically if none is specified

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Give one use case for the command: pwd

A

prints the name of the current working directory aka where you’re currently at

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Give one use case for the command: echo

A

displays a line of text aka console.log for the terminal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Give one use case for the command: touch

A

change file timestamps / update the access and modification times of each file to the current time; you can also use this to create files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Give one use case for the command: mkdir

A

make directories (if they don’t already exist)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Give one use case for the command: mv

A

move or rename files

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Give one use case for the command: rm

A

removes files or directories (done immediately and permanently)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Give one use case for the command: cp

A

copies files and directories

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is Node.js?

A

Program that allows JS to be run outside of a web browser

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What can Node.js be used for?
Build backends for web apps, command-line programs and any kind of automation
26
What is a REPL?
Read-eval-print loop Takes a single user input, executes them and returns the result to the user example: dev tool console
27
What is the process object in a Node.js program?
Global object that provides info and control over the current Node.js process aka what's happening in real time/instance of a currently running program
28
How do you access the process object in a node.js program?
You just need to reference it by name because it's global or explicitly access it using require()
29
What's the data type of process.argv in node.js?
array of strings
30
What is a javascript module?
a single .js file
31
What values are passed into a node.js module's local scope?
exports, require, module, __filename, __dirname
32
Give 2 examples of truly global variables in a node.js program
process, console, global
33
What is the purpose of module.exports in a node.js module?
To export code into another module you can assign anything to the property to make it available
34
How do you import functionality into a node.js module from another node.js module?
Use require and pass in the relative path to the file as a string
35
What is the JavaScript Event Loop?
It is a continuous process --> it basically monitors the call stack and the callback queue. It watches to see if the call stack is empty before adding the next item in the queue into the call stack
36
What is different between "blocking" and "non-blocking" with respect to how code is executed?
Blocking means that no other code can be executed until the current code is finished executing. Non-blocking means that it's asychronous --> code can continue to be executed and does not have to wait for others to finish running
37
What is a directory?
A folder
38
What is a relative path?
Path as it relates to the current working directory (where you're currently located) basically how you get to the location you want based on where you're at right now ex: you're in a store in the mall, how do you get to another store
39
What is an absolute file path?
Specifies the location of a file starting from the root directory ex: tells you how to get to a store from the entrance of the mall
40
What module does Node.js include for manipulating the file system?
Fs aka file system
41
What method is available in the Node.js fs module for writing data to a file?
writefile method
42
What is a client?
service requesters hardware or software programs that request content or service from a server
43
What is a server?
a program that shares their resources with clients
44
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
45
What three things on the start line of an HTTP request message?
1. http method: describes action to be performed 2. request target: usually a URL or absolute path 3. HTTP version:
46
What three things are on the start-line of an HTTP response message?
1. protocol version: usually HTTP/1.1 2. status code: indicating success or failure 3. status text: brief description of status code to help humans understand
47
What are HTTP headers?
provides meta-data about the message exchange
48
Is a body required for a valid HTTP request or response message?
No
49
What is NPM?
Node package manager that allows developers to share code. Consists of 3 distinct components 1. the website: used to discover packages, set up profiles 2. the CLI (command line interface): runs from terminal, how most developers interact with npm 3. the registry: large public database of JS software and meta info surrounding it
50
What is a package?
Directory with one or more files that also contains a package.json file *basically bits of reusable code*
51
How can you create a package.json with npm?
npm init --yes
52
What is a dependency and how do you add one to a package?
npm install it's basically 3rd party code that your application depends on/needs to work
53
What happens when you add a dependency to a package with npm?
package.json gets updated and a node-modules folder is created that includes the package
54
How do you add express to your package dependencies?
npm install express
55
what express application method starts the server and binds it to a network PORT?
app.listen
56
How do you mount a middleware with an express application?
app.use
57
Which objects does an express application pass to your middleware to manage the request/response lifecycle of the server?
request object (HTTP request message in the form of a data model) and response object (HTTP response message in the form of a control)
58
What is the appropriate content-type header for HTTP messages that contain JSON in their bodies?
application/json
59
What is the significance of an HTTP request's method?
it tells the server what the client wants it to do also allows the server to determine what to do in response to that request
60
What does the express.json() middleware do and when do you need it?
it parses (turns strings into usable data) the body of any request You need it when you’re adding or sending in data in the form of a request to the server
61
What is array.filter used for?
You can create an array while excluding some elements, aka create an array of items that meet your condition
62
What is array.map used for?
create a new array containing the transformed elements of another **only use map if you want to build a new array and utilize it** if not, use forEach or for ... of instead
63
What is array.reduce used for?
combining the elements of an array into a single value