Senior Side Flashcards
es6-const-let
What is a code block? What are some examples of a code block?
A code block are lines of code which are grouped together by curly braces. Some examples are for loops, if statements, and functions.
es6-const-let
What does block scope mean?
It means that the code/variable will not be accessible outside the code block (curly braces).
es6-const-let
What is the scope of a variable declared with const or let?
Block scoped
Var = function scope
es6-const-let
What is the difference between let and const?
Let can be updated, but not redeclared. Const can’t be updated nor redeclared.
Const must be initialized when it’s defined
Similarity = both const and let are blocked scoped and they’re not initialized with undefined like var keyword.
es6-const-let
Why is it possible to .push() a new value into a const variable that points to an Array?
We can change the values, in this case add, of a const variable, but we can’t reassign or redeclare it.
es6-const-let
How should you decide on which type of declaration to use?
Const variables are for things that don’t change values, let is for values that are meant to manipulated or changed.
good code doesn’t reassing var
es6-template-literals
What is the syntax for writing a template literal?
Replace all quotes for a string with backticks ( ` ` )
Can contain strings and any JavaScript expressions (anything that returns a value): ${firstName.toUpperCase()}
es6-template-literals
What is “string interpolation”?
Having expression/variables values substituted in a string. EX: ${variable_name}
es6-destructuring
What is destructuring, conceptually?
Assigning a variable to the value extracted from an object property or an array index
es6-destructuring
What is the syntax for Object destructuring?
const keyword, then curly braces { }, property key names, then equal signs = , then object name you’re destructuring from, use OR || to avoid errors after name
es6-destructuring
What is the syntax for Array destructuring?
const keyword, then square brackets [ ], elements you want, then equal signs = array name that is destructured, use OR || to avoid errors after name
es6-destructuring
How can you tell the difference between destructuring and creating Object/Array literals?
variable name at start(left)= creating literals
variable name at end(right) = destructuring literals
es6-arrow-functions
What is the syntax for defining an arrow function?
optional variable declaration, assignment operator, optional params (if 0 param then no parenthesis, if 1 param optional parenthesis, more than 1 then parentheses is needed), arrow, then a single expression or a code block
es6-arrow-functions
When an arrow function’s body is left without curly braces, what changes in its functionality?
it returns (implicitly) from the function
If using expression like ‘x + y’, then ‘return’ keyword/statement not needed.
Note: expression has a result value. statement doesn’t have a result, it is more of a command
If using curly braces then it needs ‘return’ keyword/statement.
Note: in react (expression-based) if put statement into where expression should be then it will error
es6-arrow-functions
How is the value of ‘this’ determined within an arrow function?
better to look at it as when is ‘this’ determined.
Arrow functions captures the ‘this’ value of the enclosing context rather than making its own ‘this’ (similar to how scope works)
arrow functions: ‘this’ is defined at function definition
traditional functions: ‘this’ is defined at function call
Note: in the example exercise, the setTimeout functions are being defined multiple times when the function runs (‘this’ is the jokester object with the arrow functions in setTimeout)
Note2: to bypass ‘this’ being window object when undefined (global ‘this’) then you assign ‘this’ to a variable. For example: ‘var realThis = this’
Note3: if you made the functions of the properties of jokester using ‘traditional ES5 functions’ then it would grab the global ‘this’ object because ‘this’ will be defined at function call
Note4: function names AND values are hoisted to the top, while var names are hoisted, but their values aren’t evaluated till JavaScript reaches their code line. Tim’s tip: Create functions and vars where you need them, then you can move the functions/variables around (like using utility functions at the bottom)
command-line-basics
What is a CLI?
Stands for command-line interface.
It processes commands to a computer program in the form of lines of text
command-line-basics
What is a GUI?
Stands for graphical user interface.
It is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation. Example of GUI text editor is VS Code
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: review what a command does (manual)
cat: print out contents of a file into terminal or combine contents of a file.
ls: list files in a current directory (can go to other directories if using path)
pwd: print current working directory
echo: display a line of text (string) into terminal, which can be added to a new file
touch: create a new file in current directory (if you use path then you can create the file in another directory)
mkdir: create a new directory
mv: move or rename a file (renaming something also moves it)
rm: remove/delete a file or directory (there is no undo and it doesn’t go into the trash)
cp: copy a file, which you can rename in the same line
command-line-basics
What are the three virtues of a great programmer?
- Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don’t have to answer so many questions about it.
- Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to.
- Hubris: The quality that makes you write (and maintain) programs that other people won’t want to say bad things about.
node-intro
What is Node.js?
A back-end JavaScript runtime environment (program) that operates on the Chrome V8 engine and executes JavaScript code outside of a browser.
node-intro
What can Node.js be used for?
Node.js can be used to execute JavaScript outside of the web browser. Develop command-line applications, server applications, and other back-ends.
node-intro
What is a REPL?
Stands for read, evaluate, print, and loop (loop because it waits for next input). It’s a computer environment where you can write code and execute code.
node-intro
When was Node.js created?
Node.js was created on May 27, 2009
node-intro
What back end languages have you heard of?
JavaScript (node.js), ruby, python, php, c# (.NET), perl, typescript, assembly, go, sql (for programming databases), haskell (only has functions (has to return something) and data, Tim said it changed the way he wrote JavaScript in a good way)
Scripting Languages (often interpreted): ruby, python, php, javascript, perl
Compiled Languages (analyzes source code then makes new set of code): c, c++, go, haskell, c# (.NET), f#, java, assembly (maybe compiled??), typescript
sql on it’s own
node-process
What is a computer process?
The instance of a computer program that is being executed by one or many threads. It contains the program code and its activity.
short version: instance of running program
node-process
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
500+ processes, but only 3 were listed as running
node-process
Why should a full stack Web developer know that computer processes exist?
Full stack web development is based on making multiple processes work together to form one application, so knowing about computer processes will help with making applications with clients, servers, and databases
node-process-argv
What is the ‘process’ object in a Node.js program?
It’s a global object that provides information about, and control over, the current Node.js process.
Another way: a model of the current instance of Node.js process
node-process-argv
How do you access the ‘process’ object in a Node.js program?
The 'process' object is always available (global) to Node.js applications, so you can just type 'process.' To explicitly access it then you use: const process = require('process');
node-process-argv
What is the data type of ‘process.argv’ in Node.js?
An array of strings which contains the command line arguments passed when the Node.js process was launched.
Note: means array of strings.
Note: the first element will be ‘process.execPath’ (the absolute path to where the Node.js process launched), the second element will be the name of the JavaScript file being executed, the remaining elements are any additional command line arguments.
node-module-system
What is a JavaScript module?
A JavaScript file…. which uses code from a separate file to execute its code
node-module-system
What values are passed into a Node.js module’s local scope?
‘export’ = a reference to module.exports (you can add a single thing by making it exports = ‘some string’, but its default value is an object, so an example is exports.foo = ‘bar’, which will add them as a property of the exports object)
‘require’ = used to import modules, JSON, and local files.
‘module’ = a reference to the current module
‘__filename’ = file name of the current module
‘__dirname’ = directory name of the current module
These 5 values (all local variables or parameters which are passed into a module wrapper function to know where your code is from) are passed into your module, which can then be accessed by your code
node-module-system
Give two examples of truly global variables in a Node.js program.
The ‘process’ object and the ‘global’ namespace object. ‘console’ is also another one.
In JavaScript the window object controls both variables and their process
In Node.js, the ‘process’ object controls processes and the ‘global’ object controls variables
node-require
What is the purpose of module.exports in a Node.js module?
To export the code in one JavasScript file and give access to that code to other JavaScript files
node-require
How do you import functionality into a Node.js module from another Node.js module?
const variableName
= require FUNCTION followed by parenthesis, which contains a string to the relative path of the file you want to import
the-event-loop
What is the JavaScript Event Loop?
It’s responsible for handling callbacks. Looks at the stack, if it’s clear, then look at the task/callback queue, and then push the callback onto the stack
the-event-loop
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking = operations that run synchronously (and are slow, which block further execution of JavaScript code (ex; AJAX requests)
blocking operations are happening on the stack and nothing can be executed until it is off the stack - JavaScript causes
non-blocking = operations that run asynchronously and therefore don’t block execution of JavaScript code (gets put into the callback queue)
non-blocking operations happen anywhere that’s not on stack
Note: a callback queue exists which means callbacks will not execute all at once
node-fs-readfile
What is a directory?
a file folder
node-fs-readfile
What is a relative file path?
The file path relative from the current/or some location
node-fs-readfile
What is an absolute file path?
The full path, starting from the root (in mac OS it is a slash), of a file
node-fs-readfile
What module does Node.js include for manipulating the file system?
the ‘fs’ module
stands for file system
node-fs-writefile
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile() method
node-fs-writefile
Are file operations using the fs module synchronous or asynchronous?
The ones we used are asynchronous, but there are synchronous versions
http-messages-recap
What is a client?
Service requesters - software/hardware that request info from servers
http-messages-recap
What is a server?
service providers: software/hardware that provides resource or service
note: nowadays it’s software talking to each other isntead of hardware/computer devices
http-messages-recap
Which HTTP method does a browser issue to a web server when you visit a URL?
GET method - which requests representation of data
http-messages-recap
What is on the first line of an HTTP request message?
The request header, HTTP method which describes action to be performed (GET) and then the request target (URL), protocol version
http-messages-recap
What is on the first line of an HTTP response message?
status line, with the protocol/http version and then the status code, then status text
http-messages-recap
What are HTTP headers?
Information relating to the HTTP request/response which can be modified by the client or server
short version: meta data about response/request
http-messages-recap
Is a body required for a valid HTTP message?
No, usually the status code is enough
npm-intro
What is NPM?
A package manager for the Node JavaScript platform. Puts modules so that node can find them and manage dependency conflicts
It’s actually 3 things:
- website
- cli
- registry
npm-intro
What is a package?
A package is a file or directory with package.json file in it
npm-intro
How can you create a package.json with npm?
npm init for options or npm init –yes for default package
npm-intro
What is a dependency and how to you add one to a package?
files necessary to run our code
npm install packageName
npm-intro
What happens when you add a dependency to a package with npm?
It’s added to the node_modules directory (makes one if none are found) and adds/updates dependencies property on the package.json file to have that dependency
expresss-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?
the listen() method.
first you require(‘express’) then do app = express() ‘function’, then app.listen(‘portName’)
Note: require(‘express’) returns a function unlike require(‘fs’) which returns an object
express-hello-world
How do you mount a middleware with an Express application?
the use method of app object
express-hello-world
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
req (stands for ‘request’) and res (stands for ‘response’) object
express-get-json
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
Content-Type: application/json; charset=utf-8
Note: worth noting that the headers to be arbitrary, for example it is possible for it to say application/json, but actually be an html file. So headers are just a HINT of what is in the body