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
Q

What can Node.js be used for?

A

Build backends for web apps, command-line programs and any kind of automation

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

What is a REPL?

A

Read-eval-print loop
Takes a single user input, executes them and returns the result to the user
example: dev tool console

27
Q

What is the process object in a Node.js program?

A

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
Q

How do you access the process object in a node.js program?

A

You just need to reference it by name because it’s global or explicitly access it using require()

29
Q

What’s the data type of process.argv in node.js?

A

array of strings

30
Q

What is a javascript module?

A

a single .js file

31
Q

What values are passed into a node.js module’s local scope?

A

exports, require, module, __filename, __dirname

32
Q

Give 2 examples of truly global variables in a node.js program

A

process, console, global

33
Q

What is the purpose of module.exports in a node.js module?

A

To export code into another module
you can assign anything to the property to make it available

34
Q

How do you import functionality into a node.js module from another node.js module?

A

Use require and pass in the relative path to the file as a string

35
Q

What is the JavaScript Event Loop?

A

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
Q

What is different between “blocking” and “non-blocking” with respect to how code is executed?

A

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
Q

What is a directory?

A

A folder

38
Q

What is a relative path?

A

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
Q

What is an absolute file path?

A

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
Q

What module does Node.js include for manipulating the file system?

A

Fs aka file system

41
Q

What method is available in the Node.js fs module for writing data to a file?

A

writefile method

42
Q

What is a client?

A

service requesters
hardware or software programs that request content or service from a server

43
Q

What is a server?

A

a program that shares their resources with clients

44
Q

Which HTTP method does a browser issue to a web server when you visit a URL?

A

GET method

45
Q

What three things on the start line of an HTTP request message?

A
  1. http method: describes action to be performed
  2. request target: usually a URL or absolute path
  3. HTTP version:
46
Q

What three things are on the start-line of an HTTP response message?

A
  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
Q

What are HTTP headers?

A

provides meta-data about the message exchange

48
Q

Is a body required for a valid HTTP request or response message?

A

No

49
Q

What is NPM?

A

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
Q

What is a package?

A

Directory with one or more files that also contains a package.json file
basically bits of reusable code

51
Q

How can you create a package.json with npm?

A

npm init –yes

52
Q

What is a dependency and how do you add one to a package?

A

npm install
it’s basically 3rd party code that your application depends on/needs to work

53
Q

What happens when you add a dependency to a package with npm?

A

package.json gets updated and a node-modules folder is created that includes the package

54
Q

How do you add express to your package dependencies?

A

npm install express

55
Q

what express application method starts the server and binds it to a network PORT?

A

app.listen

56
Q

How do you mount a middleware with an express application?

A

app.use

57
Q

Which objects does an express application pass to your middleware to manage the request/response lifecycle of the server?

A

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
Q

What is the appropriate content-type header for HTTP messages that contain JSON in their bodies?

A

application/json

59
Q

What is the significance of an HTTP request’s method?

A

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
Q

What does the express.json() middleware do and when do you need it?

A

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
Q

What is array.filter used for?

A

You can create an array while excluding some elements, aka create an array of items that meet your condition

62
Q

What is array.map used for?

A

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
Q

What is array.reduce used for?

A

combining the elements of an array into a single value