JavaScript Senior Flashcards

1
Q

What is “string interpolation”?

A

Substituting part of a string with javascript variables

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

What is the syntax for writing a template literal?

A

Strings ${JS variables}

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

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

A

Code between two curly braces (function, conditional, loop)

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

What does block scope mean?

A

Variable only exists in between the curly braces of the block

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

What is the scope of a variable declared with const or let?

A

Block-scoped

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

What is the difference between let and const?

A

Let – the variable can be reassigned

Const- cannot be reassigned

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

Why is it possible to .push() a new value into a const variable that points to an Array?

A

The const variable refers to the Array it refers to, not the actual values in the array

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

How should you decide on which type of declaration to use?

A

Const – if the value will always be the same
Let – if you have to reassign a value, use let
Prefer Const- use const, until you have to use let

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

What is destructuring, conceptually?

A

Take elements from an array or properties from an object and assign each to their own 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

const/let [ ] or { }

const [propertyName: newVarName, property2: varName2] = array

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

let/const varName = ( ) => { }

  • parameter ( ) are optional if there is one parameter
  • curly braces required if there is a statement
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

If there are no curly braces, the code has to be an expression that evaluates to a single value.

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

In an arrow function, ‘this’ is being determined when the arrow function is being defined. The value of ‘this’ is based on the value of ‘this’ in it’s parent code block. If parent is an arrow function as well, keep going up.

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

Shadowing

A

Inside an inner function, if a variable with the same name is declared as a variable in the outer function, the inner variable is the one accessed in that inner function and the outer variable cannot be accessed

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

CLI

A

Command Line Interfaces

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

What is Node.js?

A

Node.js is JavaScript that is not run in the browser.

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

What can Node.js be used for?

A

Used to build-back ends for web applications, command line programs, automation

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

What is a REPL?

A

Read-Evaluate-Print-loop

Takes a single user input, executes them, and prints them.

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

What back end languages have you heard of?

A
JavaScript.
Python.
PHP.
Perl.
Java.
Ruby.
C#
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the difference between JavaScript and other back end languages?

A

JavaScript has the event loop.

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

What is a computer process?

A

A computer process is the instance of a computer program that is being executed by one or more threads.

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

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

A

Full Stack Web Developers make multiple process work together to create one application.

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

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

A

It is a global object that provides info about, and control over current Node.js process

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

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

A

You can just call the ‘process’ object since it is a global variable.

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

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

A

It is an array of strings.

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

What is a JavaScript module?

A

In JS a ‘module’ is a single .js file

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

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

A
  • __dirname = directory name of current module
  • __filename = file name of current module
  • exports = reference to the module.exports
  • module = reference to the current module
  • require(id) - used to import modules, JSON, and local files
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

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

A

process

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

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

A

Whatever is assigned to exports property of a module will be available to other modules through require.

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

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

A

module.exports = variableToExport

to import:
const newVar = require('./add')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

What is the JavaScript Event Loop?

A

The event loop will then check if the call stack is empty, and then push that callback to the stack

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

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

A

Blocking - operations on the call stack that prevent other execution of code until that operation is complete
Non-blocking - code that doesn’t block execution

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

What is a directory?

A

Directory is a list of other files and directories

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

What is a relative file path?

A

Can start with: ../ (parent directory)

./ (sibling file) or nothing in the beginning

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

What is an absolute file path?

A

File that points all the way from the root directory. Starts with a slash

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

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

A

writeFile() method

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

Are file operations using the fs module synchronous or asynchronous?

A

Asynchronous and synchronous, there are both asynch and sync methods on the fs module.

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

What is NPM?

A

NPM is a software registry, consisting of
- the website
- CLI
- the registry
Where developers can use other public packages on NPM in their own projects.

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

What is a package?

A

A package is a directory with one or more files in it and a package.json with meta data in it.

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

How can you create a package.json with npm?

A

Command:

npm init -y

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

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

A

A dependency is a package required by your application.
Command:
npm install [package]

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

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

A

The dependency gets added to the package.json ‘dependencies’ object

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

How do you mount a middleware with an Express application?

A

the use method of the app object

app.use( )

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

The request object and the response object

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

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

A

Content-Type: application/json;

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

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

A

When you need take in the info from body from a post request.

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

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

A

To signify which callback function(s) to execute depending on the request method. Server can do whatever it wants with the request.

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

What is PostgreSQL and what are some alternative relational databases?

A

PostgreSQL is a relational database system.

Others include: SQLite, MySQL

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

What are some advantages of learning a relational database?

A

Most widely used kind of database, developers work with a relational database at least a little during their career. Knowing SQL is a very portable skill.

51
Q

What is one way to see if PostgreSQL is running?

A

sudo service postgresql status

52
Q

What is a database schema?

A

Collection of tables, how a database should be structured

53
Q

What is a table?

A

List of rows, with the same set of attributes(columns).

54
Q

What is a row?

A

A row is all the data that describes one item.

55
Q

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

A

SQL is the primary way of interacting with relational databases. It is a declarative language - describe the results you want and the programming environment comes up with the plan to get those results.

56
Q

How do you retrieve specific columns from a database table?

A

Using the names of attributes in “ “

select “attribute”,
“name”

57
Q

How do you filter rows based on some specific criteria?

A

Using the where clause, acts as a conditional

where "age" = '40'
58
Q

What are the benefits of formatting your SQL?

A

Consistent style and therefore readability.

59
Q

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

A

< , >, =, !=

60
Q

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

A
Using the limit clause, it is the last clause in the SQL statement
select "attribute",
           "name"
         from "classroom"
       limit 4;
61
Q

How do you retrieve all columns from a database table?

A

select *

62
Q

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

A

Using the order by clause, default is ascending order

order by “attribute”

63
Q

How do you add a row to a SQL table?

A

insert into “products” (“attribute”)

values (“value”)

64
Q

What is a tuple?

A

The list of values is referred to as a tuple.

65
Q

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

A

insert into “products” (“attribute”)
values (“value”)
(“value2”)

66
Q

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

A

returning statement.

returning *;

67
Q

How do you update rows in a database table?

A

update “products”
set “price” = 100
where “productId” = 24;

68
Q

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

A

To determine what row(s) gets updated, rather than updating every in row in the table.

69
Q

How do you delete rows from a database table?

A

delete from “products”
where “category” = ‘cleaning’
and “price” < 20

70
Q

How do you accidentally delete all rows from a table?

A

delete from “products”;

71
Q

What is a foreign key?

A

A column in one table that refers to another column in a different table, that show a relationship between the two tables.

72
Q

How do you join two SQL tables?

A

Using the ‘join’ clause

select “products”.”name” as “product”,
“suppliers”.”name” as “supplier”
from “products”
join “suppliers” using (“supplierId”);

73
Q

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

A
Using the 'as' clause
select "p"."name" as "product",
       "suppliers"."name" as "supplier"
  from "products" as "p"
  join "suppliers" using ("supplierId");
74
Q

What are some examples of aggregate functions?

A

count( )
avg( )
sum( )

75
Q

What is the purpose of a group by clause?

A

Separates rows into groups to allow us to perform aggregate functions on those groups of rows.

76
Q

What are the three states a Promise can be in?

A

pending
fulfilled
rejected

77
Q

How do you handle the fulfillment of a Promise?

A

promiseObj.then(value => {

} );

78
Q

How do you handle the rejection of a Promise?

A

promiseObj.catch( error => {

});

79
Q

What is Array.prototype.filter useful for?

A

Creating a new array from an existing array that matches a certain criteria.

80
Q

What is Array.prototype.reduce useful for?

A

Combining all the elements of an array into a single value.

81
Q

What is “refactoring”?

A

Restructuring code that does the exact same thing but may be easier to read.

82
Q

What is the typeof an ES6 class?

A

Function

83
Q

Describe ES6 class syntax.

A
class Name {
   constructor ( )

methods() {
}
}

84
Q

What is Webpack?

A

Webpack is a module bundler, purpose is to bundle JavaScript files for usage in a browser.

85
Q

How do you add a devDependency to a package?

A

npm install package –save-dev

86
Q

What is an NPM script?

A

Convenient way to bundle common shell commands to execute.

87
Q

How do you execute Webpack with npm run?

A

Create a script in package.json with name such as “build:” and set to the string “webpack”

88
Q

What kind of modules can Webpack support?

A

ECMAScript modules, CommonJS, and AMD modules

89
Q

How are ES Modules different from CommonJS modules?

A

ES Modules are officially supported in the language. They can be statically analyzed, they have a declarative syntax.

90
Q

What is React?

A

React is a JavaScript library for building user interfaces.

91
Q

What is a React element?

A

A react element is an object that describes what the DOM element should look like.

92
Q

How do you mount a React element to the DOM?

A

Using the ReactDOM.render( ) method

ReactDOM.render(element, container);

93
Q

What is Babel?

A

Babel is a JavaScript compiler mainly used to convert ECMAScript 2015 into backwards compatible version of Javascript.

94
Q

What is a Plug-in?

A

Software component that adds a specific feature to an existing computer program

95
Q

What is a Webpack loader?

A

Utilities for webpack to help webpack compile and/or transform given type of resource that can be bundle as a JavaScript bundle

96
Q

How can you make Babel and Webpack work together?

A

Installing a babel loader and using it in the webpack.config

97
Q

What is JSX?

A

JSX is a syntax extension of JavaScript.

98
Q

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

A

This is because Babel compiles JSX down to React.createElement( ) function calls to create the actual DOM specified by the JSX code.

99
Q

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

A

Using webpack.config and Babel Loader with the transform-jsx-react plug in.

100
Q

What is a React component?

A

React component is a piece of the UI that can be reused.

They return JSX that describes what the HTML React element should show on the screen.

101
Q

How do you define a function component in React?

A

Declare a function with a capitalized names that takes parameters props and returns JSX.

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}
102
Q

What are props in React?

A

props is an object that is passed to the React.createElement( ) method to use in creating the React component.

103
Q

How do you pass props to a component?

A

Inside a react component, set the attribute and assign it to a string, or JS expression.

104
Q

How do you write JavaScript expressions in JSX?

A

Using curly braces, place the JS expression in between the curly braces.
{ JavaScript expression }

105
Q

How do you create “class” component in React?

A
class ComponentName extends React.Component {
   render( ) {

}
}

106
Q

How do you access props in a class component?

A

Using the ‘this’ keyword

107
Q

What is the purpose of state in React?

A

To tell us the current state of a component.

108
Q

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

A

Pass the event as a prop to the react element and assign a JavaScript expression with the event handler function passed in.

109
Q

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

A

The map( ) method

110
Q

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

A

The ID if there is one
or
A unique value that is unique amongst its siblings

111
Q

What are controlled components?

A

Controlled components are commonly input elements that are fully controlled by React with the props: value and onChange controlling the input element.

112
Q

What does express.static() return?

A

express. static( ) return a middleware function

- can be used to serve files from specified path

113
Q

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

A

__dirname is the directory name of the current module.

114
Q

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

A

Joins all path segments together

- must be strings

115
Q

What does fetch() return?

A

fetch( ) returns a promise that resolves with a response object

116
Q

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

A

GET request

117
Q

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

A

By supplying ‘options’ in the fetch( ) call and setting the method.

118
Q

When does React call a component’s componentDidMount method?

A

Immediately after the component is mounted.

- constructor( ) and render( ) are called prior

119
Q

Name three React.Component lifecycle methods.

A

componentDidMount( )
componentDidUpdate( )
componentWillUnmount( )

120
Q

How do you pass data to a child component?

A

Through its props.

121
Q

What must the return value of myFunction be if the following expression is possible?

myFunction()();

A

myFunction must return a function.

122
Q

What does this code do?

const wrap = value => () => value;

A

Returns a function that returns value

123
Q

In JavaScript, when is a function’s scope determined; when it is called or when it is defined?

A

When the function is defined

124
Q

What allows JavaScript functions to “remember” values from their surroundings?

A

Closure, lexical scope.