ES6, Node.js Flashcards

1
Q

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

A

Statements to be executed and it’s denoted by curly braces. For example, if-else statements, for, and while loop things.

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

What does block scope mean?

A

Something that you can’t use outside of the code block because it only exists in the curly braces 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

The block scope. Opposed to function scope (var).

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

The variables declared by the let keyword are mutable therefore you can change their values anytime. But the const keyword can’t be reassigned.

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 the array value is mutable but the const value is immutable.

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

Use let and const only instead of the var keyword. Use let if the declared value needs to be reassigned and use const if it doesn’t.

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

Put the backticks on the start and end. And dollar signs with a curly brace and the name of the variable can embed the variables and expressions.

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

What is “string interpolation”?

A

It’s the ability to substitute part of the string for the 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

It unpacks the values from arrays or properties from objects and is able to reassign them to the new 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

Start with the variable declaration keyword, followed by the opening curly braces. Inside of the curly braces, put the property name by itself or property name colon with any name that you want to assign, closing the curly brace and equal sign with the original 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

Start with the variable declaration keyword, followed by the opening square bracket including the names of the new variable of the indexes, followed by the closing square bracket and equal sign with the original array 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

When creating the object or array literals, it starts with the variable declaration keyword and the name followed by an equal sign. When destructuring, it also starts with the variable declaration keyword, but the equal sign and name will be placed after the closing curly brace or closing square bracket.

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

You need parenthesis that covers your parameter, then the arrow and curly braces. You have to put parentheses if you have multiple parameters or no parameter, but you can skip the parenthesis if you have one parameter.

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

In this case, I don’t need a return statement.

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

The left side of the this (left side of the dot) will be the value of this. If there is nothing on the left then this value will be a global window.

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. It accepts text input to execute operating system functions.

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

What is a GUI?

A

Graphical User Interface. It’s an interface that uses windows, icons, and menus to enable easy interaction.

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.

A

man: When I want to see the command keyword
cat: When I want to concatenate files to standard output.
ls: When I want to see the list information about the files in the current directory.
pwd: When I want to check or print the full name of the current working directory.
echo: When I want to type in to the standard output. It
touch: When I want to update the access and modification times of each file to the current time.
mkdir: When I create the new directory.
mv: When I rename the directory name. Rename SOURCE to DEST or move SOURCE to DIRECTORY.
rm: When I want to remove the file.
cp: When I want to copy the SOURCE to DEST or multiple SOURCEs to DIRECTORY.

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, and hubris.

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

What is Node.js?

A

It’s a program that allows JavaScript to be run outside of a web browser. Node.js is powered by V8, which is the same JavaScript engine in the Google Chrome browser.

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

What can Node.js be used for?

A

It can be used when you want to execute what you write in JavaScript.

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

What is a REPL?

A

It stands for Read Eval Print Loop. It’s a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user. Ex) Console dev tools in browser.

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

When was Node.js created?

A

It was invented in 2009 by Ryan Dahl.

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

What back-end languages have you heard of?

A

Python, PHP, Ruby, Java, JavaScript, Go, Rust, C, C++, C#, Kotlin, Elixir.

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

What is a computer process?

A

It’s the instance of a computer program that is being executed by one or more threads that include the program code and its activity.

26
Q

Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?

A

Around hundred.

27
Q

Why should a full-stack Web developer know that computer processes exist?

A

Because full-stack web development means making the application with multiple processes together both the frontend and backend.

28
Q

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

A

It’s a global that provides information about, and control over, the current Node.js process.

29
Q

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

A

It’s global, it’s always included with node.js, so you can just use it whenever you need it without declaring.

30
Q

What is the data type of process.argv in Node.js?

A

It’s an array of strings.

31
Q

What is a JavaScript module?

A

It is a single .js file that can load other .js files.

32
Q

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

A

exports, require, module, __fileame, __dirname.

33
Q

Give two examples of truly global variables in a Node.js program.

A

Process, window, console.

34
Q

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

A

It allows other files to access the exported code.

35
Q

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

A

By using the require function.

36
Q

What is the JavaScript Event Loop?

A
37
Q

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

A

The blocking is, it can’t be executed together and it should be executed one by one. The non-blocking is, can be executed together.

38
Q

What is a directory?

A

It’s like a folder that allows the user to store the files in here.

39
Q

What is a relative file path?

A

It’s the location of a file or a directory relative to the current directory.

40
Q

What is an absolute file path?

A

It starts with a forward slash.

41
Q

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

A

fs module.

42
Q

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

A

The writeFile method.

43
Q

Are file operations using the fs module synchronous or asynchronous?

A

Asynchronous.

44
Q

What is a client?

A

The client is a service requester that initiates a request for a service from the server. One of the clients’ examples is the browser.

45
Q

What is a server?

A

The server is computer hardware software that provides a resource or service.

46
Q

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

A

The GET method.

47
Q

What is on the first line of an HTTP request message?

A

A method which is a verb, request target, and protocol version. In this case, GET is a verb, / is a request target, and 200 OK is the protocol version.

48
Q

What is on the first line of an HTTP response message?

A

The protocol version, status code, and status text.

49
Q

What are HTTP headers?

A

It allows the client and the server to pass additional information with an HTTP request or response.

50
Q

Is a body required for a valid HTTP message?

A

No, it is not and it’s optional.

51
Q

What is NPM?

A

NPM consists of three distinct components which are the website, the Command Line Interface (CLI), and the registry.

52
Q

What is a package?

A

It is also called modules is a reusable code on multiple programs and package is a directory with one or more files.

53
Q

How can you create a package.json with npm?

A

Navigate to the root directory of your package on the command line, type in npm init –yes or -y.

54
Q

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

A

A dependency is packages required by the application. To add one to a package, you can edit your package.json manually or use the command npm install dependency name in the right directory.

55
Q

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

A

If you add a dependency to a package, it will update your package.json so you can see “dependencies”.

56
Q

How do you add express to your package dependencies?

A

Type in the npm install express in your terminal.

57
Q

What Express application method starts the server and binds it to a network PORT?

A

The listen method.

58
Q

How do you mount a middleware with an Express application?

A

The use method.

59
Q

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

A

req and res objects which are request and response.

60
Q

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

A

The application/JSON.

61
Q

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

A

It parses incoming requests (body) with JSON payloads. It is needed when we request something with JSON form from the server.