JavaScript - Senior Flashcards

1
Q

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

A

within { } Loops / Functions / Conditionals

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

What does block scope mean?

A

Within that code block only

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

Within that code block only

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 is a value which you do not plan on changing, let is a variable which you plan to change

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 name is constant, not the contents

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

Favor const, unless you plan to reuse the variable

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

What is destructuring, conceptually?

A

Taking properties from an object or values from an array and assigning them to variables

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

What is the syntax for Object destructuring?

A

const { property list } = obj

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

What is the syntax for Array destructuring?

A

const [var 1, var2] = array

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

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

A
Literals:   const name = { }
Destructure:  const  { }  =  name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the syntax for defining an arrow function?

A

( ) if 0 args or 2 +, => { } / sometimes optional

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

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

A

Needs to be an expression. Will return that expression

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

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

A

At definition time. Will exit any arrow functions and look outside of those

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

What is Node.js?

A

An asynchronous JavaScript runtime where many connections can be handled concurrently.

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

What can Node.js be used for?

A

Back-end, Command-line app, or any kind of automation that developers wish to perform.

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

What is a REPL?

A

Read eval print loop, like a console, it prints any expression given

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

When was Node.js created?

A

2009

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

What back end languages have you heard of?

A
Ruby
PHP
Java
C#
Python
C
C++
Swift (not common for back end though feasible)
Objective C (not common for back end though feasible)
JavaScript
Perl
Go
Erlang
Elixir
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is a CLI?

A

Command Line Interface

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

What is a GUI?

A

Graphical User Interface

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
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 = manuals
cat  =  printing contents of a file
ls  = lists the folders and files
pwd  =  prints the current directory
echo   = prints
touch  =  creates a file if it doesn't exist
mkdir  = makes a directory
mv   = moves or renames directory
rm   =  remove file or directory
cp   = copy a file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is a computer process?

A

The execution of instructions

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

To be able to tie things together

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

An object that contains info about a node 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

process / globally available

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

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

A

array of strings

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

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

A

exports, require, module, __filename, __dirname

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

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

A

global / process

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

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

A

This is what the module returns when being called with require / Alternatively you can use a named export (exports.add)

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

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

A

require( path )

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

What is the JavaScript Event Loop?

A

It controls the Queue and puts things back onto the stack

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

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

A

Blocking means that nothing else can take place during this request, while non-blocking means that it sends it off and other things can happen in the meantime

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

What is a directory?

A

folder

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

What is a relative file path?

A

doesn’t start with /

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

What is an absolute file path?

A

starts with slash, at the root

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

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

A

fs

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

What is NPM?

A

CLI for sharing code / Website / Registry

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

What is a package?

A

A folder that has at least one file with a package.json file

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 –yes

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

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

A

npm install name…

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 adds it to your package.json and it downloads it into the node modules folder

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

.listen( )

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

How do you mount a middleware with an Express application?

A

app.use( )

46
Q

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

A

req / res

47
Q

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

A

application/json

48
Q

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

A

semantics / you can make it do whatever you like, although we would want to stick to convention

49
Q

What does res.status(403).end() accomplish?

A

Sets the status and closes the response

50
Q

What does res.status(400).send(‘Bad Request’) accomplish?

A

Sets the status and sends back data

51
Q

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

A

It converts json to objects, you would need if you are trying to access the data in form of objects

52
Q

What are the three states a Promise can be in?

A

pending / fulfilled / rejected

53
Q

How do you handle the fulfillment of a Promise?

A

promise.then(callback)

54
Q

How do you handle the rejection of a Promise?

A

promise.catch(callback)

55
Q

What is Array.prototype.filter useful for?

A

To filter out specific values based on a function and add them to a new array

56
Q

What is Array.prototype.map useful for?

A

To perform an operation on each element based on a function and add them to a new array

57
Q

What is Array.prototype.reduce useful for?

A

To get one value out of all the elements in the array

58
Q

What can arguments.length be used for?

A

To check whether optional parameters were supplied in a function call

59
Q

What is “syntactic sugar”?

A

Makes code easier with same functionality

60
Q

What is the typeof an ES6 class?

A

function

61
Q

Describe ES6 class syntax.

A
class Name {
constructor(params) {  }
func( )
}
62
Q

What is “refactoring”?

A

Rewriting code to simplify, same functionality

63
Q

What is Webpack?

A

Something that bundles together all your code for better performance

64
Q

How do you add a devDependency to a package?

A

npm install packagename –save-dev

65
Q

What is an NPM script?

A

you assign an alias for a command prompt to be used as a shortcut

66
Q

How do you execute Webpack with npm run?

A

npm run scriptAlias

67
Q

How are ES Modules different from CommonJS modules?

A

Different syntax “import from etc”

68
Q

What kind of modules can Webpack support?

A

CommonJS / AMD / ES modules

69
Q

How do you export with ES modules

A

If named export (not default) then with name and { } where importing
If default, then doesn’t need { } and you can use any name you want

70
Q

What is React?

A

A JavaScript library for UI

71
Q

What is a React element?

A

An object

72
Q

How do you mount a React element to the DOM?

A

ReactDom.render( )

73
Q

What is Babel?

A

A tool which can be used to convert your code to alternate syntax

74
Q

What is a Plug-in?

A

A addition to a piece of software which adds functionality

75
Q

What is a Webpack loader?

A

Loaders are transformations that are applied to the source code

76
Q

How can you make Babel and Webpack work together?

A

Babel loader

77
Q

What is JSX?

A

An XML-type syntax as an extension to JavaScript

78
Q

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

A

Because in order to render the JSX it needs to create a React element

79
Q

How can you make Webpack and Babel work together to convert JSX into valid JavaScript?

A

babel loader with a jsx plug-in

80
Q

What is a React component?

A

function or a class which returns a React component

81
Q

How do you define a function component in React?

A

function Component (Must start with uppercase)

82
Q

How do you mount a component to the DOM?

A

ReactDom.render(element, container)

83
Q

What is the difference between a library and a framework?

A

with a library you tell it what and when to do, with a framework it decides when to run your code etc

84
Q

What are props in React?

A

An objects which has properties

85
Q

How do you pass props to a component?

A

With a property name

86
Q

How do you write JavaScript expressions in JSX?

A

{ }

87
Q

How do you create “class” component in React?

A
class Name extends React.Component
render()
88
Q

How do you access props in a class component?

A

this.props

89
Q

What does bind mean?

A

To have a function store “this” from where it is at right now even though it is called somewhere else (in a callback)

90
Q

What does lexical scope mean?

A

That inner functions have access to variables in outer function

91
Q

What does closures mean?

A

That inner functions still have access to variables in outer function even if they are called somewhere else (callback functions)

92
Q

What is the purpose of state in React?

A

To keep track of changes and update the UI

93
Q

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

A

onClick = { eventHandler }

94
Q

What is the purpose of state in React?

A

To keep track of the current status and watch out for change

95
Q

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

A

onClick= { }

96
Q

What does virtual DOM mean?

A

React keeps a copy of the DOM and only rerenders the part that it needs to

97
Q

What are controlled components?

A

When the react component that renders a form also controls what happens in that form on subsequent user input.

98
Q

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

A

value =

onChange { handler }

99
Q

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

A

array.map

100
Q

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

A

The best way to pick a key is to use a string that uniquely identifies each list item. Often you would use IDs from your data as keys:

101
Q

What does express.static() return?

A

A function that can handle requests to serve files in that path

102
Q

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

A

The folder that contains the module

103
Q

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

A

combine fragments of a path

104
Q

What does fetch() return?

A

A Promise that resolves to a Response object.

105
Q

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

A

Get

106
Q

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

A

{ method: post } as second argument

107
Q

What does res.json( ) do?

A

Reads the body until completion / then parses the response

108
Q

When does React call a component’s componentDidMount method?

A

When it renders the first time

109
Q

Name three React.Component lifecycle methods.

A

constructor > render > componentdidmount

110
Q

How do you pass data to a child component?

A

via props

111
Q

How does the && operator work?

A

It returns the first falsy value or the last truthy

112
Q

What is props.children?

A

Any thing that you put in between custom React elements