ES6 & Node Flashcards

1
Q

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

A

Code block = code between curly braces

Examples: function definitions, if-block, else-block, loop body…etc

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

What does block scope mean?

A

Means the binding of the variable only applies in the current 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

variables declared using const and let are block scoped

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

const -> variable can’t be assigned to a different value; variable also has to be given a value at the time it is declared

let -> variable is mutable (aka can be reassigned) and can be declared without initializing (giving it a value)

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

const means that this variable always points to the same reference/location in memory. However the value at that location in memory can change.

The variable declared with const always points at the array but the value of elements in the array can be changed

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 const whenever possible; if not possible, use let.

in general the scope of a binding should be as specific as possible

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

String surrounded by backticks; embedded js variables and expressions inside ${ }

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

What is “string interpolation”?

A

substituting values into placeholders in a template string

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

What is destructuring, conceptually?

A

Syntax shortcut for assigning properties of an object/elements of an array to individual variables.

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 { property1: alias1, property2: alias2 } = objName;

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 arr = [1, 2, 3];
const [ var1, var2, var3 ] = arr;
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

Creating object/array literal -> object/array literal on right side of assignment operator

Destructuring assignment -> things that looks like an object/array literal on left side of assignment operator

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

(parameters) => {
functionBody
}

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

Implicit return

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

Determined by the enclosing lexical scope.

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

Graphical user interface

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

What is Node.js?

A

Javascript that runs outside/independent of browser.

more technically.

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

What can Node.js be used for?

A

Pretty much anything since it’s no longer restricted to the browser.
Usually used for building backends of web applications (server-side scripting), command-line tools, automating tasks.

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

What is a REPL?

A

Read-Eval(uate)-Print loop; a simple programming environment; it’s a place to test out snippets of the language

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

When was Node.js created?

A

2009

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

What is a computer process?

A

An application running on your computer

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

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

A

Full stack Web development is based on making multiple processes (backend/server, frontend/client, and database) work together to form one application

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

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

A

A global variable in all Node programs ‘that provides information about, and control over, the current Node.js process’.

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

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

A

It a global variable so you can access it by typing process

26
Q

What is a JavaScript module?

A

a .js file

27
Q

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

A
  1. exports
  2. module
  3. __filename
  4. __dirname
  5. require
28
Q

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

A

process object, global object, console object…and others

29
Q

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

A

Specifies what values/functions of a module should be available to other modules

30
Q

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

A

Use the require function

31
Q

What is the JavaScript Event Loop?

A

Event loop is the thing that allows js code to look like there is concurrency even though it is single threaded.

It moves tasks between callstack and event queue, and monitors events and tasks for completion.

In browser, it is also in charge of rendering the page and re-rendering it when changes have been made to DOM.

32
Q

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

A

Blocking code prevents the program from doing anything else until its task is finished. When it is executed, it doesn’t leave the callstack until it is complete.

Non-blocking code still lets other code run if it has to wait for something (aka ‘does not pause execution of other functions in the function stack’);
Is is asynchronous.

Gets moved from call stack to event queue by event loop ; then moved back to call stack when it is time to execute call back

33
Q

What is a directory?

A

Component of the file system that groups files together; contains references to other files and possibly directories

34
Q

What is a relative file path?

A

File path that starts from current directory

35
Q

What is an absolute file path?

A

File path always starts from root directory. (aka the start of the hard drive)

36
Q

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

A

The fs module

37
Q

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

A

writeFile() method

38
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

39
Q

What is NPM?

A

A software registry used for sharing/downloading packages.

‘NPM’ also used to refer to the NPM website, and the NPM CLI

The NPM CLI is used to install libraries you want to use in your Node/JavaScript application

40
Q

What is a package?

A

a file or directory that is described by a package.json file

41
Q

How can you create a package.json with npm?

A

use the ‘npm init’ command in the NPM CLI

42
Q

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

A

It’s added to the package.json and the package’s code is put in the directory node_modules

43
Q

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

A

A dependency is code written by someone else that your app uses
(ex. if you write a javascript application that uses jQuery, then your app has jQuery as a dependency

Add a dependency
using the command ‘npm install’ in the NPM CLI

44
Q

How do you add express to your package dependencies?

A

npm install express

45
Q

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

A

app.listen()

46
Q

How do you mount a middleware with an Express application?

A

app.use() method

47
Q

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

A
  1. request object
  2. response object
  3. next object (function)
48
Q

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

A

Content-Type: application/json; charset=utf-8

49
Q

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

A

The server handles the requests to the same endpoint differently depending on what the method of the request is.

50
Q

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

A

It parses the JSON in requests that have JSON in the request body and puts the parsed data at req.body

Use when your server expects to receive JSON data from client

51
Q

What is Array.prototype.filter useful for?

A

getting a subset of existing data

eg. picking values from array of objects, searching for value in array

52
Q

What is Array.prototype.map useful for?

A

Anytime you want to perform some action on every element of an array and save the results

53
Q

What is Array.prototype.reduce useful for?

A

Combining the elements of an array into a single value.

54
Q

What is “syntactic sugar”?

A

Syntax whose only purpose is to make something more convenient to use or easier to read

55
Q

What is the typeof an ES6 class?

A

function

56
Q

Describe ES6 class syntax.

A
class className {
	constructor(constructorParam) {
	    this.instanceVariable = 
                 constructorParam;
	}
method1() { . . .

method2() {

} }
57
Q

What is “refactoring”?

A

Changing how a piece of functionality/a feature is implemented without changing its functionality

58
Q

What are the three states a Promise can be in?

A
  1. Fulfilled 2. pending 3. rejected
59
Q

How do you handle the fulfillment of a Promise?

A

.then() method

60
Q

How do you handle the rejection of a Promise?

A

.catch() method