ES6/Node.js/npm/express Flashcards

(92 cards)

1
Q

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

A

A code block is sets of code that are enclosed in {} curly braces. An example would be a function 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

Variables that exist only when they are within a block?
What happens in the code block, it stays inside the code block

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

blocked scope variable

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

What is the difference between let and const?

A

let variables can be reassigned while const variables cannot

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

Because we are not reassigning the array itself, we are adding new variables into the array

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

You should use let when you know you are going to reassign the variable. And typically use const when you know you are not going to change it.

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

${variable_name}

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

What is “string interpolation”?

A

It is a feature that has the ability to sub parts of a string with values of variables or expressions

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

What is destructuring, conceptually?

A

breaking down arrays or objects and giving values and properties a variable

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

What is the syntax for Object destructuring?

A

const or let {object_properties} = object_name;

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

What is the syntax for array destructuring?

A

const or let [variable_names] = object_name;

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

How can you tell the difference between destructuring and creating Object/Array literals?

A

by seeing which side the equal sign shows up

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

What is the syntax for defining an arrow function?

A

let myFunction = (…args) => expression

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

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

A

nothing, only use curly braces for block syntax

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

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

A

it captures the value of the enclosing context instead of creating its own

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

What is a CLI?

A

command line interface

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

What is a GUI?

A

graphic user interface

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

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

A

man (manual) - man cat
cat (outputs contents) - cat example.txt
ls (list of files) - ls example/
pwd (presents working directory) - pwd
echo (display line of text) - echo ‘Hello, World!’
touch (change file timestamps and file creation) - touch create-file.txt
mkdir (make directories) - mkdir example
mv (move or rename files) - mv pokimans pokemon
rm (remove files) - rm example.txt
cp (copy files and directories) - cp example.txt example2.txt

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

What are the three virtues of a great programmer?

A

laziness, impatience, hubris

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

What are the 3 components of a fullstack Web architecture?

A

presentation(frontend), logic(backend), data tiers

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

What is Node.js?

A

designed to build scalable network applications as an asynchronous event-driven JavaScript runtime for servers

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

What can Node.js be used for?

A

server side of javascript, to get requests from the server

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

What is a REPL?

A

Read–eval–print loop takes single user inputs, executes them, and returns the result to the user

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

When was Node.js created?

A

May 27, 2009

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What backend languages have you heard of?
Ruby, PHP, Java
26
What is a computer process?
an instance of a computer program being executed by one or more threads
27
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
a lot (mine has 420 processes)
28
Why should a full stack Web developer know that computer processes exist?
so you know how your application interacts with the operating system (OS) and hardware
29
What is the process object in a Node.js program?
provides information about, and control over, the current Node.js process
30
How do you access the process object in a Node.js program?
process
31
What is the data type of process.argv in Node.js?
an array of strings
32
How do you access the command line arguments in a Node.js program?
process.argv[2]
33
What is a JavaScript module?
it is a single '.js' file and node is made up of multiple modules
34
What are the advantages of modular programming?
since you are breaking a big solution/problems into a lot of smaller ones, it can be an advantage by being able to be more organized with your code as well as help you solve parts at a time
35
In JavaScript, how do you make a function in a module available to other modules?
by exporting
36
In JavaScript, how do you use a function from another module?
by importing
37
What is the JavaScript Event Loop?
a series of code/calls waiting or in queue to be put in the call stack where the code will execute
38
What is different between "blocking" and "non-blocking" with respect to how code is executed?
blocking is code that blocks further execution until the operation is finished while non-blocking is code that doesn't block further executions
39
What are the three states a Promise can be in?
pending, fulfilled, rejected
40
How do you handle the fulfillment of a Promise?
by using .then(value)
41
How do you handle the rejection of a Promise?
by using .catch(error)
42
What does Array.filter do?
it filters out values in an array based on the callback function
43
What should the callback function return?
a boolean
44
What is Array.filter useful for?
when filtering out specific values and elements in an array
45
What does Array.map do?
it creates a new array filled with the new values from the function
46
What should the callback function return?
a new array with the result of the function
47
What is Array.map useful for?
so that you can keep the original array
48
What does Array.reduce do?
process and reduce an array of values to a single value
49
What action should the callback function perform?
it should take two parameters, the accumulator and the current value, it goes through each iteration of the accumulator
50
What should the callback function return?
it should return accumulated value at each iteration from the callback function
51
What is Array.reduce useful for?
its useful when you need to transform an array of values into a single value
52
What is a directory?
a folder
53
What is a relative file path?
a file that is relative to the current directory that is being worked on
54
What is an absolute file path?
a file that is found through the root directory
55
What module does Node.js include for manipulating the file system?
the fs file system
56
What method is available in the node:fs module for reading data from a file?
the fileRead method, you have to import 'node:fs', and then call it with (path, option)
57
What method is available in the node:fs module for writing data to a file?
the writeFile method, you have to import 'node:fs' and then call it (file, data, option, callback)
58
Are file operations using the fs module synchronous or asynchronous?
asynchronous
59
What is a client?
a client is a piece of hardware or software that is used by the server for the client-server-model, it usually sends a request to another program so that it accesses a service made for the server
60
What is a server?
it's a piece of hardware or software that provides the functionality for other programs (clients)
61
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method
62
What is on the first line of an HTTP request message?
request method, request target, and version GET https://example.com HTTP/1.1
63
What is on the first line of an HTTP response message?
protocol version, status code, status text HTTP/1.1 403 Forbidden
64
What are HTTP headers?
it adds additional info/context for the request
65
Is a body required for a valid HTTP message?
No
66
What is NPM?
node package manager, is open source that allows people to share and borrow packages
67
What is a package?
a directory with one or more files that includes the package.json file
68
How can you create a package.json with npm?
first navigate to the root directory and then use npm init -yes
69
What is a dependency and how do you add one to a package?
it's a package that is depended on another package, you can add one by using the command npm install
70
What happens when you add a dependency to a package with npm?
the devDependencies will get stored in the package.json file and it will create a node_module file
71
What are some other popular package managers?
npm, Yarn, PNPM, Homebrew
72
What is Express useful for?
express is useful for building web applications as it helps Node manage servers and routes
73
How does Express fit into a full-stack web application?
it manages the http request (we can think of it as a middle man between frontend and backend
74
How do you add express to your package dependencies?
by installing express npm install express
75
What Express application method starts the server and binds it to a network PORT?
the listen() method
76
What is Express middleware?
functions that are executed between the processing of a request and the sending of a response.
77
What is Express middleware useful for?
it executes in between a request and a response (it can be used for authentications, data parsing, logging, and error handling)
78
How do you mount a middleware with an Express application?
by using the .use() method
79
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
the request and response objects and next function
80
What is an API endpoint?
the url
81
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
82
What is the significance of an HTTP request's method?
it allows the client to perform actions on the server (retrieving, creating, updating, and deleting data)
83
What does the express.json() middleware do and when would you need it?
it is a built in function that takes the requests and parses the JSON data into an object and puts it on req.body
84
What is the purpose of the Express Static middleware?
to process static files in an express app
85
What does express.static() return?
a middleware function that serves static files
86
What are several examples of static files?
HTML, CSS, images
87
What is a good way to serve application images using Express?
88
How to start express app:
cd directory_name -> npm init -> npm install express -> npm install nodemon
89
What does fetch() return?
a promise that resolves to the response object
90
What is the default request method used by fetch()?
GET
91
How do you specify the request method (GET, POST, etc.) when calling fetch?
{method: method_name} as the second argument of the fetch() callback function
92
How does fetch report errors?
try and catch