JavaScript (Senior Side) Flashcards
What is a code block? What are some examples of a code block?
a structure that consists of one or more declarations and statements. I.e. function code block, conditional code block, loop code block.
What does block scope mean?
Anything within the code block can only be accessed within the code block.
What is the scope of a variable declared with const or let?
block
What is the difference between let and const?
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.
Why is it possible to .push() a new value into a const variable that points to an Array?
Because if const is an arrray or an object, its properties or items can be updated or removed.
How should you decide on which type of declaration to use? (Const or let)
Consider whether or not the value of the variable will need to be changed in the future.
What is the syntax for writing a template literal?
backticks ( ` ` )
use $ { } to insert variables
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions.
When an arrow function’s body is left without curly braces, what changes in its functionality?
It can only return one expression
What is destructuring, conceptually?
a syntax that allows us to get specific properties of an object and store them in a variable
What is the syntax for Object destructuring?
const { value } = variable
What is a CLI?
Command Line Interface
What is the syntax for Array destructuring?
const [array] = variable
How can you tell the difference between destructuring and creating Object/Array literals?
the operands are reversed
What is the syntax for defining an arrow function?
(param) => {
}
How is the value of this determined within an arrow function?
It captures the value of the enclosing context instead of creating its own this context.
What are the three virtues of a great programmer?
Laziness
Impatience
Hubris
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of the web browser.
What can Node.js be used for?
1.back ends for Web applications
2.command-line programs
3.any kind of automation that developers wish to perform.
What is a REPL?
Read-Eval-Print-Loop. it is an interactive shell that processes Node. js expressions.
When was Node.js created?
May 27, 2009
What is the process object in a Node.js program?
a global that provides information about, and control over, the current Node.js process.
How do you access the process object in a Node.js program?
type out the process variable
What is the data type of process.argv in Node.js?
array
What is a JavaScript module?
a single .js file.
What 4 values are passed into a Node.js module’s local scope?
.exports
.require
__filename
__dirname
Give two examples of truly global variables in a Node.js program.
console
process
What is the purpose of module.exports in a Node.js module?
to be able to reuse values from other other modules
How do you import functionality into a Node.js module from another Node.js module?
with the require ( ) function
What 3 things does the JS Event Loop do?
1.) executes the code
2.) collects and processes events
3.) executes queued sub-tasks.
What is different between “blocking” and “non-blocking” with respect to how code is executed?
Blocking code is synchronous
Non-blocking is asynchronous
What is a directory?
something that holds files and folders
What is a relative file path?
A path that refers to a location that is relative to a current directory.
What is an absolute file path?
a path that contains the root element and the complete directory list required to locate the file.
What module does Node.js include for manipulating the file system?
the ‘fs’ module
What method is available in the Node.js fs module for writing data to a file?
fs.writefile( )
Are file operations using the fs module synchronous or asynchronous?
asynchronous
What is NPM?
Node Package Manager
open source software registry for developers
What is a package?
a file that can be downloaded and used in a program
How can you create a package.json with npm?
npm init -y command
What is a dependency and how to you add one to a package?
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
What happens when you add a dependency to a package with npm?
it is added to the node modules directory
How do you add express to your package dependencies?
npm install express
What Express application method starts the server and binds it to a network PORT?
the listen method
What is a GUI?
Graphical User Interface
How do you mount a middleware with an Express application?
app.use ( )
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request object, response object, next object
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application / json
What is the significance of an HTTP request’s method?
they indicate the desired action to be performed for a given resource.
What does the express.json() middleware do and when would you need it?
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
What is PostgreSQL and what are some alternative relational databases?
It is an open source, relational database management system. Other examples include MySQL, SQL server, and oracle
What are (3) advantages of learning a relational database?
- You can store and use data sets that are
related to each other. - Data corruption is unlikely
- Support good guarantees about data
integrity
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
A collection of tables
What is a table?
a list of rows each having the same set of attributes.
What is a row?
contains a set of attributes
What is SQL and how is it different from languages like JavaScript?
1.) It’s a programming language that allows you to interact with relational databases
2.) it is declarative rather than imperative
How do you retrieve specific columns from a database table?
with the “select” keyword followed by the “name” of column, followed by “from”
How do you filter rows based on some specific criteria?
with the “where” clause
What are the benefits of formatting your SQL?
its easier to read
What are four comparison operators that can be used in a where clause?
= < > !=
How do you limit the number of rows returned in a result set?
the “limit” clause
How do you retrieve all columns from a database table?
with an asterisk *
How do you control the sort order of a result set?
with the “order by” clause
How do you add a row to a SQL table?
with the “insert” and “into” keywords
What is a tuple?
one row / a list of values
How do you add multiple rows to a SQL table at once?
add the headers / top row
add values below, and insert each new row of values into a new ( ) below the previous
How do you get back the row being inserted into a table without a separate select statement?
with the “returning” keyword
How do you update rows in a database table?
with the update and set statements
Why is it important to include a where clause in your update statements?
because if you don’t, you will end up updating every row in the table
How do you delete rows from a database table?
delete statement
How do you accidentally delete all rows from a table?
DONT SPECIFY “WHERE”
What is a foreign key?
a field or column in one table that points to another table
How do you join two SQL tables?
use the “join” keyword
How do you temporarily rename columns or tables in a SQL statement?
use an alias
What are some examples of aggregate functions?
every ( ), count ( ) , avg ( )
What is the purpose of a group by clause?
when you want to separate rows into groups and perform aggregate functions on those groups of rows
What are the three states a Promise can be in?
pending: initial state, neither fulfilled nor rejected.
fulfilled: meaning that the operation was completed successfully.
rejected: meaning that the operation failed.
How do you handle the fulfillment of a Promise?
with the .then method
How do you handle the rejection of a Promise?
with the .catch method
What is Array.prototype.filter useful for?
quickly getting desired array values that meet the specified criteria
What is Array.prototype.map useful for?
calling a provided function on every element in an array, and then returning a new array with the results
What is Array.prototype.reduce useful for?
combining all the contents of an array into a single value
What is “syntactic sugar”?
syntax within a programming language that is designed to make things easier to read or to express.
What is the typeof an ES6 class?
function
Describe ES6 class syntax.
class Name {
constructor (name) {
} function ( ) { } }
What is “refactoring”?
the process of restructuring existing computer code to better organize it while not changing its functionality.
What is Webpack?
a tool that lets you bundle your JavaScript applications (supporting both ESM and CommonJS)
How do you add a devDependency to a package?
with the “npm install –save-dev” command
What is an NPM script?
a convenient way to bundle common shell commands for your project.
How do you execute Webpack with npm run?
use the “npm run build” command
Name 3 ways that ES Modules are different from CommonJS modules
1.) Slightly more complicated syntax
2.) Designed for asynchronous loading
3.) Main use: browser
What 3 kind of modules can Webpack support?
1.es modules
2. commonJS
3. AMD
What is React?
React is a JavaScript library / framework for creating user interfaces.
What is a React element?
a DOM element created using React
How do you mount a React element to the DOM?
create root method, pass in react element, and render the root object
What is Babel?
a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript
What is a Plug-in?
a software component that adds a specific feature to an existing computer program.
What is a Webpack loader?
transformations that allow you to pre-process files as you import or “load” them.
What dev dependency do you need to make Babel and Webpack work together?
the “babel loader”
What is JSX?
a syntax extension to JavaScript using react
Why must the React object be imported when authoring JSX in a module?
access to the React objects is needed
What 2 dev dependencies can make Webpack and Babel work together to convert JSX into valid JavaScript?
1.) ‘babel loader”
2.) @babel/plugin-transform-react-jsx
What is a React component?
they are like javascript functions, and accept arbitrary inputs (called “props”) and return React elements describing what should appear on the screen
How do you define a function component in React?
function Name (props) {
}
How do you mount a component to the DOM?
- query dom for div with id of “root” and save to a const named “container”
- call createRoot method of ReactDOM object and pass in container
- call render method of root object and pass in ( < createdElement />) from the render function
What are props in React?
objects used to pass data to a component
How do you pass props to a component?
with { props } syntax
How do you write JavaScript expressions in JSX?
The same way you’d write them in JS
How do you create “class” component in React?
with the className keyword
How do you access props in a class component?
with the “this” keyword
What is the purpose of state in React?
To give you more control over a component
How to you pass an event handler to a React element?
you provide a listener as a property (“onClick, “onSubmit”) when the element is initially rendered.
What are controlled components?
An input form element whose value is controlled by React via “state”
What two props must you pass to an input for it to be “controlled”?
value, event handler
What Array method is commonly used to create a list of React elements?
.map ( )
What is the best value to use as a “key” prop when rendering lists?
use something that uniquely identifies a list item among its siblings.
What does express.static() return?
serves static files from the specified “root” argument (data type is a function)
What is the local __dirname variable in a Node.js module?
The directory name of the current module.
What does the join() method of Node’s path module do?
joins all specified path segments that are entered as arguments into one path
What does fetch() return?
a promise that is fulfilled once the response is available.
What is the default request method used by fetch()?
GET
How do you specify the request method (GET, POST, etc.) when calling fetch?
put it as the second argument, inside of an object:
{ method: GET }
When does React call a component’s componentDidMount method?
immediately after the component is rendered to the DOM
Name three React.Component lifecycle methods.
render, constructor, componentDidMount
How do you pass data to a child component?
use “props”
What does the acronym LIFO mean?
Last In First Out
What methods are available on a Stack data structure?
.peek ( )
.print( )
.push( )
.pop( )
What must you do to access the value at an arbitrary point in a stack (not just the “top”)?
keep using .pop( ) until you reach the item you want
What does the acronym FIFO mean?
first in first out
What methods are available on a Queue data structure?
enqueue(value)
dequeue( )
print( )
peek( )
What must you do to access the value at an arbitrary point in a queue (not just the “front”)?
use dequeue( ) until you reach the item you want
How are linked lists different from an array?
they contain nodes
How would you access an arbitrary node in a linked list (not just the “head”)?
the .next( ) method