JavaScript (Senior Side) Flashcards

1
Q

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

A

a structure that consists of one or more declarations and statements. I.e. function code block, conditional 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

Anything within the code block can only be accessed within 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

block

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 value of const can’t be changed through reassignment and it can’t be redeclared.

The value of let can be changed through reassignment and it can be redeclared.

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 if const is an arrray or an object, its properties or items can be updated or removed.

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? (Const or let)

A

Consider whether or not the value of the variable will need to be changed in the future.

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

backticks ( ` ` )

use $ { } to insert variables

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

What is “string interpolation”?

A

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

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

A

It can only return one expression

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

What is destructuring, conceptually?

A

a syntax that allows us to get specific properties of an object and store them in a variable

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

What is the syntax for Object destructuring?

A

const { value } = variable

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

What is a CLI?

A

Command Line Interface

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

What is the syntax for Array destructuring?

A

const [array] = variable

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

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

A

the operands are reversed

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

What is the syntax for defining an arrow function?

A

(param) => {

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
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 this context.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
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
18
Q

What is Node.js?

A

Node.js is a program that allows JavaScript to be run outside of the web browser.

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

1.back ends for Web applications

2.command-line programs

3.any kind of automation that developers wish to perform.

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

What is a REPL?

A

Read-Eval-Print-Loop. it is an interactive shell that processes Node. js expressions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
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
22
Q

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

A

a global 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
23
Q

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

A

type out the process variable

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

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

A

array

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

What is a JavaScript module?

A

a single .js file.

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

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

A

.exports

.require

__filename

__dirname

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

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

A

console

process

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

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

A

to be able to reuse values from other other modules

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

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

A

with the require ( ) function

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

What 3 things does the JS Event Loop do?

A

1.) executes the code
2.) collects and processes events
3.) executes queued sub-tasks.

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

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

A

Blocking code is synchronous

Non-blocking is asynchronous

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

What is a directory?

A

something that holds files and folders

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

What is a relative file path?

A

A path that refers to a location that is relative to a current directory.

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

What is an absolute file path?

A

a path that contains the root element and the complete directory list required to locate the file.

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

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

A

the ‘fs’ module

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

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

A

fs.writefile( )

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

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

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

What is NPM?

A

Node Package Manager

open source software registry for developers

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

What is a package?

A

a file that can be downloaded and used in a program

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

How can you create a package.json with npm?

A

npm init -y command

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

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

A

A dependency is a third-party bit of software that was probably written by someone else and ideally solves a single problem for you.

it is installed with npm.install

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

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

A

it is added to the node modules directory

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

How do you add express to your package dependencies?

A

npm install express

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

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

A

the listen method

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

What is a GUI?

A

Graphical User Interface

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

How do you mount a middleware with an Express application?

A

app.use ( )

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

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

A

request object, response object, next object

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

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

A

application / json

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

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

A

they indicate the desired action to be performed for a given resource.

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

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

A

Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches the type option.

you need it when working with server requests and responses

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

What is PostgreSQL and what are some alternative relational databases?

A

It is an open source, relational database management system. Other examples include MySQL, SQL server, and oracle

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

What are (3) advantages of learning a relational database?

A
  1. You can store and use data sets that are
    related to each other.
  2. Data corruption is unlikely
  3. Support good guarantees about data
    integrity
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

What is one way to see if PostgreSQL is running?

A

sudo service postgresql status

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

What is a database schema?

A

A collection of tables

55
Q

What is a table?

A

a list of rows each having the same set of attributes.

56
Q

What is a row?

A

contains a set of attributes

57
Q

What is SQL and how is it different from languages like JavaScript?

A

1.) It’s a programming language that allows you to interact with relational databases
2.) it is declarative rather than imperative

58
Q

How do you retrieve specific columns from a database table?

A

with the “select” keyword followed by the “name” of column, followed by “from”

59
Q

How do you filter rows based on some specific criteria?

A

with the “where” clause

60
Q

What are the benefits of formatting your SQL?

A

its easier to read

61
Q

What are four comparison operators that can be used in a where clause?

A

= < > !=

62
Q

How do you limit the number of rows returned in a result set?

A

the “limit” clause

63
Q

How do you retrieve all columns from a database table?

A

with an asterisk *

64
Q

How do you control the sort order of a result set?

A

with the “order by” clause

65
Q

How do you add a row to a SQL table?

A

with the “insert” and “into” keywords

66
Q

What is a tuple?

A

one row / a list of values

67
Q

How do you add multiple rows to a SQL table at once?

A

add the headers / top row

add values below, and insert each new row of values into a new ( ) below the previous

68
Q

How do you get back the row being inserted into a table without a separate select statement?

A

with the “returning” keyword

69
Q

How do you update rows in a database table?

A

with the update and set statements

70
Q

Why is it important to include a where clause in your update statements?

A

because if you don’t, you will end up updating every row in the table

71
Q

How do you delete rows from a database table?

A

delete statement

72
Q

How do you accidentally delete all rows from a table?

A

DONT SPECIFY “WHERE”

73
Q

What is a foreign key?

A

a field or column in one table that points to another table

74
Q

How do you join two SQL tables?

A

use the “join” keyword

75
Q

How do you temporarily rename columns or tables in a SQL statement?

A

use an alias

76
Q

What are some examples of aggregate functions?

A

every ( ), count ( ) , avg ( )

77
Q

What is the purpose of a group by clause?

A

when you want to separate rows into groups and perform aggregate functions on those groups of rows

78
Q

What are the three states a Promise can be in?

A

pending: initial state, neither fulfilled nor rejected.
fulfilled: meaning that the operation was completed successfully.
rejected: meaning that the operation failed.

79
Q

How do you handle the fulfillment of a Promise?

A

with the .then method

80
Q

How do you handle the rejection of a Promise?

A

with the .catch method

81
Q

What is Array.prototype.filter useful for?

A

quickly getting desired array values that meet the specified criteria

82
Q

What is Array.prototype.map useful for?

A

calling a provided function on every element in an array, and then returning a new array with the results

83
Q

What is Array.prototype.reduce useful for?

A

combining all the contents of an array into a single value

84
Q

What is “syntactic sugar”?

A

syntax within a programming language that is designed to make things easier to read or to express.

85
Q

What is the typeof an ES6 class?

A

function

86
Q

Describe ES6 class syntax.

A

class Name {
constructor (name) {

}
function ( ) {
 
} }
87
Q

What is “refactoring”?

A

the process of restructuring existing computer code to better organize it while not changing its functionality.

88
Q

What is Webpack?

A

a tool that lets you bundle your JavaScript applications (supporting both ESM and CommonJS)

89
Q

How do you add a devDependency to a package?

A

with the “npm install –save-dev” command

90
Q

What is an NPM script?

A

a convenient way to bundle common shell commands for your project.

91
Q

How do you execute Webpack with npm run?

A

use the “npm run build” command

92
Q

Name 3 ways that ES Modules are different from CommonJS modules

A

1.) Slightly more complicated syntax
2.) Designed for asynchronous loading
3.) Main use: browser

93
Q

What 3 kind of modules can Webpack support?

A

1.es modules
2. commonJS
3. AMD

94
Q

What is React?

A

React is a JavaScript library / framework for creating user interfaces.

95
Q

What is a React element?

A

a DOM element created using React

96
Q

How do you mount a React element to the DOM?

A

create root method, pass in react element, and render the root object

97
Q

What is Babel?

A

a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript

98
Q

What is a Plug-in?

A

a software component that adds a specific feature to an existing computer program.

99
Q

What is a Webpack loader?

A

transformations that allow you to pre-process files as you import or “load” them.

100
Q

What dev dependency do you need to make Babel and Webpack work together?

A

the “babel loader”

101
Q

What is JSX?

A

a syntax extension to JavaScript using react

102
Q

Why must the React object be imported when authoring JSX in a module?

A

access to the React objects is needed

103
Q

What 2 dev dependencies can make Webpack and Babel work together to convert JSX into valid JavaScript?

A

1.) ‘babel loader”
2.) @babel/plugin-transform-react-jsx

104
Q

What is a React component?

A

they are like javascript functions, and accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen

105
Q

How do you define a function component in React?

A

function Name (props) {

}

106
Q

How do you mount a component to the DOM?

A
  1. query dom for div with id of “root” and save to a const named “container”
  2. call createRoot method of ReactDOM object and pass in container
  3. call render method of root object and pass in ( < createdElement />) from the render function
107
Q

What are props in React?

A

objects used to pass data to a component

108
Q

How do you pass props to a component?

A

with { props } syntax

109
Q

How do you write JavaScript expressions in JSX?

A

The same way you’d write them in JS

110
Q

How do you create “class” component in React?

A

with the className keyword

111
Q

How do you access props in a class component?

A

with the “this” keyword

112
Q

What is the purpose of state in React?

A

To give you more control over a component

113
Q

How to you pass an event handler to a React element?

A

you provide a listener as a property (“onClick, “onSubmit”) when the element is initially rendered.

114
Q

What are controlled components?

A

An input form element whose value is controlled by React via “state”

115
Q

What two props must you pass to an input for it to be “controlled”?

A

value, event handler

116
Q

What Array method is commonly used to create a list of React elements?

A

.map ( )

117
Q

What is the best value to use as a “key” prop when rendering lists?

A

use something that uniquely identifies a list item among its siblings.

118
Q

What does express.static() return?

A

serves static files from the specified “root” argument (data type is a function)

119
Q

What is the local __dirname variable in a Node.js module?

A

The directory name of the current module.

120
Q

What does the join() method of Node’s path module do?

A

joins all specified path segments that are entered as arguments into one path

121
Q

What does fetch() return?

A

a promise that is fulfilled once the response is available.

122
Q

What is the default request method used by fetch()?

A

GET

123
Q

How do you specify the request method (GET, POST, etc.) when calling fetch?

A

put it as the second argument, inside of an object:

{ method: GET }

124
Q

When does React call a component’s componentDidMount method?

A

immediately after the component is rendered to the DOM

125
Q

Name three React.Component lifecycle methods.

A

render, constructor, componentDidMount

126
Q

How do you pass data to a child component?

A

use “props”

127
Q

What does the acronym LIFO mean?

A

Last In First Out

128
Q

What methods are available on a Stack data structure?

A

.peek ( )
.print( )
.push( )
.pop( )

129
Q

What must you do to access the value at an arbitrary point in a stack (not just the “top”)?

A

keep using .pop( ) until you reach the item you want

130
Q

What does the acronym FIFO mean?

A

first in first out

131
Q

What methods are available on a Queue data structure?

A

enqueue(value)
dequeue( )
print( )
peek( )

132
Q

What must you do to access the value at an arbitrary point in a queue (not just the “front”)?

A

use dequeue( ) until you reach the item you want

133
Q

How are linked lists different from an array?

A

they contain nodes

134
Q

How would you access an arbitrary node in a linked list (not just the “head”)?

A

the .next( ) method