JavaScript Senior Flashcards
What is “string interpolation”?
Substituting part of a string with javascript variables
What is the syntax for writing a template literal?
Strings ${JS variables}
What is a code block? What are some examples of a code block?
Code between two curly braces (function, conditional, loop)
What does block scope mean?
Variable only exists in between the curly braces of the block
What is the scope of a variable declared with const or let?
Block-scoped
What is the difference between let and const?
Let – the variable can be reassigned
Const- cannot be reassigned
Why is it possible to .push() a new value into a const variable that points to an Array?
The const variable refers to the Array it refers to, not the actual values in the array
How should you decide on which type of declaration to use?
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
What is destructuring, conceptually?
Take elements from an array or properties from an object and assign each to their own variable.
What is the syntax for Object destructuring?
const/let [ ] or { }
const [propertyName: newVarName, property2: varName2] = array
What is the syntax for defining an arrow function?
let/const varName = ( ) => { }
- parameter ( ) are optional if there is one parameter
- curly braces required if there is a statement
When an arrow function’s body is left without curly braces, what changes in its functionality?
If there are no curly braces, the code has to be an expression that evaluates to a single value.
How is the value of ‘this’ determined within an arrow function?
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.
Shadowing
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
CLI
Command Line Interfaces
What is Node.js?
Node.js is JavaScript that is not run in the browser.
What can Node.js be used for?
Used to build-back ends for web applications, command line programs, automation
What is a REPL?
Read-Evaluate-Print-loop
Takes a single user input, executes them, and prints them.
What back end languages have you heard of?
JavaScript. Python. PHP. Perl. Java. Ruby. C#
What is the difference between JavaScript and other back end languages?
JavaScript has the event loop.
What is a computer process?
A computer process is the instance of a computer program that is being executed by one or more threads.
Why should a full stack Web developer know that computer processes exist?
Full Stack Web Developers make multiple process work together to create one application.
What is the process object in a Node.js program?
It is a global object that provides info about, and control over current Node.js process
How do you access the process object in a Node.js program?
You can just call the ‘process’ object since it is a global variable.
What is the data type of process.argv in Node.js?
It is an array of strings.
What is a JavaScript module?
In JS a ‘module’ is a single .js file
What values are passed into a Node.js module’s local scope?
- __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
Give two examples of truly global variables in a Node.js program.
process
What is the purpose of module.exports in a Node.js module?
Whatever is assigned to exports property of a module will be available to other modules through require.
How do you import functionality into a Node.js module from another Node.js module?
module.exports = variableToExport
to import: const newVar = require('./add')
What is the JavaScript Event Loop?
The event loop will then check if the call stack is empty, and then push that callback to the stack
What is different between “blocking” and “non-blocking” with respect to how code is executed?
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
What is a directory?
Directory is a list of other files and directories
What is a relative file path?
Can start with: ../ (parent directory)
./ (sibling file) or nothing in the beginning
What is an absolute file path?
File that points all the way from the root directory. Starts with a slash
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?
writeFile() method
Are file operations using the fs module synchronous or asynchronous?
Asynchronous and synchronous, there are both asynch and sync methods on the fs module.
What is NPM?
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.
What is a package?
A package is a directory with one or more files in it and a package.json with meta data in it.
How can you create a package.json with npm?
Command:
npm init -y
What is a dependency and how to you add one to a package?
A dependency is a package required by your application.
Command:
npm install [package]
What happens when you add a dependency to a package with npm?
The dependency gets added to the package.json ‘dependencies’ object
How do you mount a middleware with an Express application?
the use method of the app object
app.use( )
How do you mount a middleware with an Express application?
The request object and the response object
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
Content-Type: application/json;
What does the express.json() middleware do and when would you need it?
When you need take in the info from body from a post request.
What is the significance of an HTTP request’s method?
To signify which callback function(s) to execute depending on the request method. Server can do whatever it wants with the request.
What is PostgreSQL and what are some alternative relational databases?
PostgreSQL is a relational database system.
Others include: SQLite, MySQL