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
How do you access the process object in a Node.js program?
process / globally available
26
What is the data type of process.argv in Node.js?
array of strings
27
What is a JavaScript module?
a single JS file
28
What values are passed into a Node.js module's local scope?
exports, require, module, __filename, __dirname
29
Give two examples of truly global variables in a Node.js program.
global / process
30
What is the purpose of module.exports in a Node.js module?
This is what the module returns when being called with require / Alternatively you can use a named export (exports.add)
31
How do you import functionality into a Node.js module from another Node.js module?
require( path )
32
What is the JavaScript Event Loop?
It controls the Queue and puts things back onto the stack
33
What is different between "blocking" and "non-blocking" with respect to how code is executed?
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
34
What is a directory?
folder
35
What is a relative file path?
doesn't start with /
36
What is an absolute file path?
starts with slash, at the root
37
What module does Node.js include for manipulating the file system?
fs
38
What is NPM?
CLI for sharing code / Website / Registry
39
What is a package?
A folder that has at least one file with a package.json file
40
How can you create a package.json with npm?
npm init --yes
41
What is a dependency and how do you add one to a package?
npm install name...
42
What happens when you add a dependency to a package with npm?
it adds it to your package.json and it downloads it into the node modules folder
43
How do you add express to your package dependencies?
npm install express
44
What Express application method starts the server and binds it to a network PORT?
.listen( )
45
How do you mount a middleware with an Express application?
app.use( )
46
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req / res
47
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
48
What is the significance of an HTTP request's method?
semantics / you can make it do whatever you like, although we would want to stick to convention
49
What does res.status(403).end() accomplish?
Sets the status and closes the response
50
What does res.status(400).send('Bad Request') accomplish?
Sets the status and sends back data
51
What does the express.json() middleware do and when would you need it?
It converts json to objects, you would need if you are trying to access the data in form of objects
52
What are the three states a Promise can be in?
pending / fulfilled / rejected
53
How do you handle the fulfillment of a Promise?
promise.then(callback)
54
How do you handle the rejection of a Promise?
promise.catch(callback)
55
What is Array.prototype.filter useful for?
To filter out specific values based on a function and add them to a new array
56
What is Array.prototype.map useful for?
To perform an operation on each element based on a function and add them to a new array
57
What is Array.prototype.reduce useful for?
To get one value out of all the elements in the array
58
What can arguments.length be used for?
To check whether optional parameters were supplied in a function call
59
What is "syntactic sugar"?
Makes code easier with same functionality
60
What is the typeof an ES6 class?
function
61
Describe ES6 class syntax.
``` class Name { constructor(params) { } func( ) } ```
62
What is "refactoring"?
Rewriting code to simplify, same functionality
63
What is Webpack?
Something that bundles together all your code for better performance
64
How do you add a devDependency to a package?
npm install packagename --save-dev
65
What is an NPM script?
you assign an alias for a command prompt to be used as a shortcut
66
How do you execute Webpack with npm run?
npm run scriptAlias
67
How are ES Modules different from CommonJS modules?
Different syntax "import from etc"
68
What kind of modules can Webpack support?
CommonJS / AMD / ES modules
69
How do you export with ES modules
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
What is React?
A JavaScript library for UI
71
What is a React element?
An object
72
How do you mount a React element to the DOM?
ReactDom.render( )
73
What is Babel?
A tool which can be used to convert your code to alternate syntax
74
What is a Plug-in?
A addition to a piece of software which adds functionality
75
What is a Webpack loader?
Loaders are transformations that are applied to the source code
76
How can you make Babel and Webpack work together?
Babel loader
77
What is JSX?
An XML-type syntax as an extension to JavaScript
78
Why must the React object be imported when authoring JSX in a module?
Because in order to render the JSX it needs to create a React element
79
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
babel loader with a jsx plug-in
80
What is a React component?
function or a class which returns a React component
81
How do you define a function component in React?
function Component (Must start with uppercase)
82
How do you mount a component to the DOM?
ReactDom.render(element, container)
83
What is the difference between a library and a framework?
with a library you tell it what and when to do, with a framework it decides when to run your code etc
84
What are props in React?
An objects which has properties
85
How do you pass props to a component?
With a property name
86
How do you write JavaScript expressions in JSX?
{ }
87
How do you create "class" component in React?
``` class Name extends React.Component render() ```
88
How do you access props in a class component?
this.props
89
What does bind mean?
To have a function store "this" from where it is at right now even though it is called somewhere else (in a callback)
90
What does lexical scope mean?
That inner functions have access to variables in outer function
91
What does closures mean?
That inner functions still have access to variables in outer function even if they are called somewhere else (callback functions)
92
What is the purpose of state in React?
To keep track of changes and update the UI
93
How to you pass an event handler to a React element?
onClick = { eventHandler }
94
What is the purpose of state in React?
To keep track of the current status and watch out for change
95
How do you pass an event handler to a React element?
onClick= { }
96
What does virtual DOM mean?
React keeps a copy of the DOM and only rerenders the part that it needs to
97
What are controlled components?
When the react component that renders a form also controls what happens in that form on subsequent user input.
98
What two props must you pass to an input for it to be "controlled"?
value = | onChange { handler }
99
What Array method is commonly used to create a list of React elements?
array.map
100
What is the best value to use as a "key" prop when rendering lists?
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
What does express.static() return?
A function that can handle requests to serve files in that path
102
What is the local __dirname variable in a Node.js module?
The folder that contains the module
103
What does the join() method of Node's path module do?
combine fragments of a path
104
What does fetch() return?
A Promise that resolves to a Response object.
105
What is the default request method used by fetch()?
Get
106
How do you specify the request method (GET, POST, etc.) when calling fetch?
{ method: post } as second argument
107
What does res.json( ) do?
Reads the body until completion / then parses the response
108
When does React call a component's componentDidMount method?
When it renders the first time
109
Name three React.Component lifecycle methods.
constructor > render > componentdidmount
110
How do you pass data to a child component?
via props
111
How does the && operator work?
It returns the first falsy value or the last truthy
112
What is props.children?
Any thing that you put in between custom React elements