ES6 Flashcards
What is a code block? What are some examples of a code block?
code written inside the bracket {}
function bodys
loops
conditional
What does block scope mean?
something only existing inside the block
What is the scope of a variable declared with const or let?
block scope
What is the difference between let and const?
let variable can be reassigned const cant be reassigned
Why is it possible to .push() a new value into a const variable that points to an Array?
the const variable, in this case, an array, itself is immutable; on the other hand, the array itself is mutable - meaning, you can add new things to the array; think reassignment
What is the syntax for writing a template literal?
` `
What is the syntax for writing a template literal?
${expression}
What is “string interpolation”?
the ability to substitute part of the string for the values of variables or expressions.
What is destructuring conceptually?
takes values from arrays, or properties from objects, into distinct variables.
What is the syntax for Object destructuring?
const or let {propertyname} = object
What is the syntax for Array destructuring?
const or let or var [variable name ] = array
How can you tell the difference between destructuring and creating Object/Array literals?
if the array or object is on the left side then it destructuring
What is the syntax for defining an arrow function?
var keyword function = arguements => expresion let func = (arg1, arg2, ..., argN) => expression
When an arrow function’s body is left without curly braces, what changes in its functionality?
you can only have 1 line of code no curly braces no return keyword and it has to be an expression
How is the value of this determined within an arrow function?
based on the code block where the method is called
this is determined by call time based on its parents cod block
What is a CLI?
command line interface
What is a GUI?
graphical line interface
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 is the manual
cat is when you want to add more than 1 file together
ls list directory contents
pwd returns working directory name
echo write arguments to the standard output
touch changes file access and modification times
mkdir makes directories
mv moves files or renames
rm removes files
cp makes a copy of the files
What are the three virtues of a great programmer?
laziness, impatience, and hubris.
What is Node.js?
a program that allows JavaScript in to be run outside of a web browser
What can Node.js be used for?
To build back ends for Web applications, command-line programs or any automation for devs to use
What is a REPL?
It is a quick and easy way to test simple Node.js/JavaScript code
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
C# Java JS C++ Go VBA PHP Ruby Python Rust Haskell Pascal Perl Lisp C Clojure Rust Objective-C Swift Kotlin Julia Haskell Pas
What is a computer process?
The instance of a computer program that is being executed by one or many threads
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
more than 100
Why should a full stack Web developer know that computer processes exist?
they should know how processes are working together to make an application work
What is the process object in a Node.js program?
is 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?
just call it its global
What is the data type of process.argv in Node.js?
array of strings
What is a JavaScript module?
a “module” is a single .js file
What values are passed into a Node.js module’s local scope?
filename dirname module require and exports
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?
the instruction that tells Node. js which bits of code (functions, objects, strings, etc.) to “export” from a given file so other files are allowed to access the exported code
How do you import functionality into a Node.js module from another Node.js module?
call the require and use the correct file path
What is the JavaScript Event Loop?
Cycles through the call stack and checks if theres anything in the task queue and pushes that to the task queue
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking is execution must wait till other code is completed
none blocking doesnt block the code from being executed
What is a directory?
a collection of files typically created for organizational purposes
What is a relative file path?
refers to a location that is relative to a current directory
What is an absolute file path?
path always 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?
fs module
What method is available in the Node.js fs module for writing data to a file?
writefile
Are file operations using the fs module synchronous or asynchronous?
fs module are both synchronous and asynchronus
What is NPM?
NPM is a software registry. Where developers can share and borrow reusable code. it can mean the website cli registry
What is a package?
A file or directory that is describes by a package.json
How can you create a package.json with npm?
inside the root directory run the command
npm init –yes
What is a dependency and how to you add one to a package?
Packages required by your application in production.
You can add dependencies to a package.json file from the command line or by manually editing the package.json file npm install name of pacakge
What happens when you add a dependency to a package with npm?
npm add dependencies to to package.json theres a node module directory created as well
How do you add express to your package dependencies?
npm install express adds to package.json
What Express application method starts the server and binds it to a network PORT?
listen()
What is a client?
Requests a service made available by a server
What is a server?
Provides the services that the client requests
Which HTTP method does a browser issue to a web server when you visit a URL?Which HTTP method does a browser issue to a web server when you visit a URL?
GET
What is on the first line of an HTTP request message?
The HTTP method like (GET, POST, AND PUT)
What is on the first line of an HTTP response message?
The protocol version
What are HTTP headers?
Let the client and the server pass additional information with an HTTP request or response.
Is a body required for a valid HTTP message?
No
How do you mount a middleware with an Express application?
use()
Which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request object and response object
What is the appropriate Content-Type header for HTTP messages that contain JSON in their bodies?
application/json
What does the express.json() middleware do and when would you need it?
parses incoming json body from ,we will need it
What is PostgreSQL and what are some alternative relational databases?
Free, open source Relational Database Management System (RDBMS).
Microsoft SQL. MySQL. Oracle Database IBM Db2 SAP HANA Amazon Relational Database Service (RDS) SQLite
MariaDB
What are some advantages of learning a relational database?
Data Accuracy
Easy Access to Data
They are used everywhere
What is one way to see if PostgreSQL is running?
sudo service postgresql status
What is a database schema?
A collection of tables. It defines how the data in a relational database should be organized
What is a table?
A table is a list of rows each having the same set of attributes
What is a row?
set of related data
What is SQL and how is it different from languages like JavaScript?
SQL is the most common language for extracting and organizing data that is stored in a relational database. SQL is declarative programming where you can describe the results and imperative programming like JS youre on charge on have to write specific ways on how to get there
How do you retrieve specific columns from a database table?
use select clause followed by the column you want
select “column”
How do you filter rows based on some specific criteria?
use clause where followed what you want filtered and assign and operator of what you want it filtered by
where “column” = ‘false’;
What are the benefits of formatting your SQL?
makes the code more easier to read and understand making it more efficient
How do you limit the number of rows returned in a result set?
use limit keyword followed by number you want to limit
How do you limit the number of rows returned in a result set?
use limit clause followed by number you want to limit
How do you retrieve all columns from a database table?
use * on select clause
select *
How do you control the sort order of a result set?
use desc or asc on clause order by
order by “column desc
How do you add a row to a SQL table?
insert into clause
insert into “products” (“name”, “description”, “price”, “category”)
values (‘Ostrich Pillow’, ‘Feel comfy and cozy!’, 99, ‘self care’)
What is a tuple?
group of values in the parenthesis
How do you add multiple rows to a SQL table at once?
use values keyword then comma to seperate
How do you get back the row being inserted into a table without a separate select statement?
before you end with semicolon use returning clause with an *
How do you update rows in a database table?
update clause followed by the table name
set clause column name and assigning the new value
update “products”
set “price” = 100;
Why is it important to include a where clause in your update statements?
to get specific rows you want to updated if not they will all be updated
How do you delete rows from a database table?
delete from clause then the table
How do you accidentally delete all rows from a table?
if you omit the where clause itll delete all rows
delete from “products”
where “productId” = 24
What is a foreign key?
shared attributes in tables
How do you join two SQL tables?
join “name of table” using (“column name”)
What are some examples of aggregate functions?
MIN, MAX, AVG, SUM, and COUNT.
What is the purpose of a group by clause?
used to group rows that have the same values
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?
.then(callback)
How do you handle the rejection of a Promise?
.catch(callback)
How do you handle the rejection of a Promise?
.catch(callback)
What is Array.prototype.filter useful for?
to give you back elements in an array that you specify for
What is Array.prototype.map useful for?
transform each element of an array and put the new transformation into a new array
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(a,b,c,d){ this.a =a this.b = b this.c = c } more methods }
What is “refactoring”?
altering its internal structure without changing its external behavior.
What is “refactoring”?
altering its internal structure without changing its external behavior.
What is Webpack?
takes all modules in your main js and puts them all together and uses it
How do you add a devDependency to a package?
npm install –save-dev ‘name of package’
What is an NPM script?
allows you to define script commands using the scripts field in the package.json file.
How do you execute Webpack with npm run?
check if command is in the script and run the name of the property
How are ES Modules different from CommonJS modules?
es6 modules statically called, commonjs are dynamic,commonjs use module.exports property
What kind of modules can Webpack support?
ECMAScript modules. CommonJS modules. AMD modules.
What is React?
React is a JavaScript library for creating user interfaces.
What is a React element?
an object what gets returned from components
How do you mount a React element to the DOM?
ReactDOM.render(element, container[, callback])
What is Babel?
Convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments
What is a Plug-in?
Software component that adds a specific feature to an existing computer program.
What is a Webpack loader?
transformation that is applied to the the source code of a module
How can you make Babel and Webpack work together?
npm install –save-dev babel-loader
What is JSX?
a syntax extension to JavaScript
Why must the React object be imported when authoring JSX in a module?
you need to import react so that the complied output could call the create element
How can you make Webpack and Babel work together to convert JSX into valid JavaScript?
webpack will take plain js and bundle it together babel plugin
What is a React component?
Components let you split the UI into independent, reusable pieces, and think about each piece in isolation
How do you define a function component in React?
function and capitalize name with parameters if there is and it has to return a react element
How do you mount a component to the DOM?
render dom method and mount elements
What are props in React?
its object of arguments passed into React components
How do you write JavaScript expressions in JSX?
you have to surround the JavaScript code in { } brackets
How do you pass props to a component?
react element attribute and assign a string or a js expression
How do you create “class” component in React?
class key word name of funciton extends component property render function ex.(class CustomButton extends React.Component { render() { return {this.props.text}; }
How do you access props in a class component?
with “this” object
What is the purpose of state in React?
to represent info of the component current state
How to you pass an event handler to a React element?
the property onclick{function}
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?
To use a string that uniquely identifies a list item among its siblings
What are controlled components?
elements whose value is controlled by React
What two props must you pass to an input for it to be “controlled”?
value and onchange
What does express.static() return?
middleware function that returns an object
What is the local __dirname variable in a Node.js module?
the file path
What does the join() method of Node’s path module do?
joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path
What does fetch() return?
a promise for a response
What is the default request method used by fetch()?
get request
How do you specify the request method (GET, POST, etc.) when calling fetch?
init object 2nd parameter
fetch(‘/some-url,
method: “trace”)
call what method and what put what ever method you want
When does React call a component’s componentDidMount method?
after the component gets mounted on the DOM
Name three React.Component lifecycle methods.
Mounting, Updating and Unmounting.
How do you pass data to a child component?
through the props
What must the return value of myFunction be if the following expression is possible?
myFunction()();
Return value has to be a function definition.
What does this code do? const wrap = value => () => value;
Returns a function that returns value.
In JavaScript, when is a function’s scope determined; when it is called or when it is defined?
when its defined
What allows JavaScript functions to “remember” values from their surroundings?
closure