SENIOR SIDE Flashcards
ES6-CONST-LET
What is a code block? What are some examples of a code block?
a code block is anything within curly braces.
i.e. function code block, if statements, etc.
ES6-CONST-LET
What does block scope mean?
it means that variable declared within the code block are only for that block, i.e. local vs global variables
ES6-CONST-LET
What is the scope of a variable declared with const or let?
block scope
ES6-CONST-LET
What is the difference between let and const?
VAR Yes Yes Function Scope Yes
LET Yes No Block Scope No
CONST No No Block Scope No
ES6-CONST-LET
Why is it possible to .push() a new value into a const variable that points to an Array?
When you’re adding to an array or object you’re not re-assigning or re-declaring the constant, it’s already declared and assigned, you’re just adding to the “list” that the constant points to.
ex: we are not changing the typeof in the variable
ES6-CONST-LET
How should you decide on which type of declaration to use?
whether or not you ever want that variable to be redeclared or reassigned???
ES6-TEMPLATE-LITERALS
What is the syntax for writing a template literal?
` some text and ${some variable or property}`
ES6-TEMPLATE-LITERALS
What is “string interpolation”?
string interpolation is the process of evaluating a string literal containing one or more placeholders ${someVariable}, yielding a result in which the placeholders are replaced with their corresponding values.
ES6-DESTRUCTURING
What is destructuring, conceptually?
it is breaking down an object or array and assigning key/value pairs to a variable/value pair
ES6-DESTRUCTURING
What is the syntax for Object destructuring?
name = {
firstName: ‘Andy’,
lastName: ‘Chen’
}
const { firstName, lastName } = name
- this creates a variable named firstName with value of name.firstName and variable named lastName with a value of name.lastName
const { myName: firstName } = name
- this creates a variable named myName with value of name.firstName
ES6-DESTRUCTURING
What is the syntax for Array destructuring?
const someArray = [0 , 1, 2, 3, 4]
const [number1, number2, number3] = someArray
or to get the last ones after number3 then
const [ , , , number4] = someArray
ES6-DESTRUCTURING
How can you tell the difference between destructuring and creating Object/Array literals?
braces on the right side of the equal sign are creating
braces on left-hand side and that’s destructuring
ES6-ARROW-FUNCTIONS
What is the syntax for defining an arrow function?
const functionName = parameter => expression
or const functionName = (param1, param2) => param1 + param2
or const functionName = (param1, param2) => ( {param1:param2} )
ES6-ARROW-FUNCTIONS
When an arrow function’s body is left without curly braces, what changes in its functionality?
it has an implicit return
ES6-ARROW-FUNCTIONS
How is the value of ‘this’ determined within an arrow function?
arrow functions have a lexical scope (using global variables) so the value of ‘this’ is determined by the surrounding scope.
i.e. either window if it’s a global scope or local variable if arrow function is wrapped in a regular function
tim : arrow function = ‘this’ is defined at definition time
regular function = ‘this’ is defined at call time
COMMAND-LINE-BASICS
What is a CLI?
command line interface
COMMAND-LINE-BASICS
What is a GUI?
Graphical user interface
COMMAND-LINE-BASICS
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
man = ultimate guide cat = combine files ls = check file directories pwd = print current working directory echo = print to terminal, like a console.log touch = create a new file mkdir = make directories / files mv = move and renames file rm = remove a file cp = copy a file
COMMAND-LINE-BASICS
What are the three virtues of a great programmer?
laziness, impatience, and hubris???
NODE-INTRO
What is Node.js?
Node.js is a javascript runtime. A program that allows JavaScript to be run outside of a web browser.
NODE-INTRO
What can Node.js be used for?
non-blocking, event driven servers
NODE-INTRO
What is a REPL?
read-eval-print loop, interactive top level or language shell
NODE-INTRO
When was Node.js created?
2009
NODE-INTRO
What back end languages have you heard of?
Python, MySQL, Node.js
NODE-PROCESS-ARGV
What is the process object in a Node.js program?
It is an essential component in the Node.js ecosystem as it provides various information sets about the runtime of a program.
NODE-PROCESS-ARGV
How do you access the process object in a Node.js program?
const process = require('process'); or just using process since it's global
NODE-PROCESS-ARGV
What is the data type of process.argv in Node.js?
, an array of strings
NODE-MODULE-SYSTEM
What is a JavaScript module?
a JavaScript file containing related code
NODE-MODULE-SYSTEM
What values are passed into a Node.js module’s local scope?
exports, require, module, __filename, __dirname
ex: (function (exports, require, module, \_\_filename, \_\_dirname) { // your code is here });
NODE-MODULE-SYSTEM
Give two examples of truly global variables in a Node.js program.
setInterval, setTimeOut
NODE-REQUIRE
What is the purpose of module.exports in a Node.js module?
to export functions to another node.js module
NODE-REQUIRE
How do you import functionality into a Node.js module from another Node.js module?
const someVariable = require(‘./someFileName’);
THE-EVENT-LOOP
What is the JavaScript Event Loop?
An event loop is something that pulls stuff out of the queue and places it onto the function execution stack whenever the function stack becomes empty.
THE-EVENT-LOOP
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking = synchronous, won’t allow the computer to do anything else until the code block is completely run through
non-blocking = asynchronous can run other things while waiting
NODE-FS-READFILE
What is a directory?
it is a path to what people call a folder
NODE-FS-READFILE
What is a relative file path?
it is the actual file path to go from one directory to another
NODE-FS-READFILE
What is an absolute file path?
a file path from the root
NODE-FS-READFILE
What module does Node.js include for manipulating the file system?
fs module
NODE-FS-WRITEFILE
What method is available in the Node.js fs module for writing data to a file?
writeFile method
NODE-FS-WRITEFILE
Are file operations using the fs module synchronous or asynchronous?
asynchronous
HTTP-MESSAGES-RECAP
What is a client?
a device that request services
HTTP-MESSAGES-RECAP
What is a server?
something that responds to client requests
HTTP-MESSAGES-RECAP
Which HTTP method does a browser issue to a web server when you visit a URL?
GET
HTTP-MESSAGES-RECAP
What is on the first line of an HTTP request message?
start line (3 items)
- http method (GET, PUT or POST)
- URL
- HTTP version ( HTTP/1.1)
HTTP-MESSAGES-RECAP
What is on the first line of an HTTP response message?
protocol version, status code, status text
HTTP-MESSAGES-RECAP
What are HTTP headers?
meta data formatted as key:value pairs
HTTP-MESSAGES-RECAP
Is a body required for a valid HTTP message?
no
NPM-INTRO
What is NPM?
stands for Node Package Manager
- largest JS database of free code, used to share and download code
- website, CLI, and registry
NPM-INTRO
What is a package?
package.json and directory with 1 or more files in it
NPM-INTRO
How can you create a package.json with npm?
npm init –yes
NPM-INTRO
What is a dependency and how to you add one to a package?
something that the package will need to run and
to download it use npm install on command line
NPM-INTRO
What happens when you add a dependency to a package with npm?
- dependencies object will be updated
- adds the node list to the package
EXPRESS-INTRO
How do you add express to your package dependencies?
npm install express
EXPRESS-INTRO
What Express application method starts the server and binds it to a network PORT?
listen method
- Binds and listens for connections on the specified host and port