All Flashcards
URL stands for?
Uniform Resource Locator
Amazon’s full secure home URL
https://www.amazon.com
HTTPS stands for?
Hypertext Transfer Protocol Secure
The command to generate a React project inside the current directory.
npx create-react-app ./
Install command needed to use SASS
npm install node-sass
HTML stands for?
Hypertext Markup Language
CSS stands for?
Cascading Style Sheets
BEM stands for?
Block Element Modifier
In the URL, https://www.amazon.com/home
What is the ‘amazon.com’ part called?
Domain
In the URL, https://www.amazon.com/home
What is the ‘/home’ part called?
Path
IP Address stands for?
Internet Protocol Address
What is 104.59.62.31 an example of?
IP address
An IP address is a network device’s ___ ___.
unique identifier
DNS Server stands for?
Domain Name System Server
PEMDAS stands for?
Parenthasis Exponent Multiplication Division Addition Subtraction
Acronym used to represent the order of math operations in Javascript
PEMDAS
REPL stands for?
Read Evaluate Print Loop
Acronym used to represent console operations.
REPL
List of JS falsy values.
false, 0, “”, null, undefined, NaN
false, 0, “”, null, undefined, NaN are Falsy values.
All other values are __.
Truthy
The “for of” loop works on ___ like arrays and strings.
itterables
The “for in” loop works on ___.
objects
CORS stands for?
Cross-Origin Resource Sharing
Give HTML comment with “some msg” inside.
HTML5 declaration tag
Default shortcut key to toggle Word-wrap mode in VSC.
alt + z
What are the Font Awesome Icon types for fas, far, fal, fab, fad, in that order.
solid regular light brand duotone
Font Awesome icon to make svg 3 times larger.
fa-3x
# fill in the blank: \_\_\_(255, 255, 255, 0.4) returns a transparent shade of white
rgba
f00
red
0f0
green
00f
blue
fff
white
000
black
ff0
yellow
f0f
fuchsia or magenta
0ff
cyan or aqua
What is the hex code for the HTML color ‘green’?
008000
0f0
line
box-shadow: 2px 2px 2px 2px rgba(0,0,0,.5)
What are these values called from left to right?
horizontal offset
vertical offset
blur
radius
color
List all of the functions available for the CSS filter property.
blur()
brightness()
contrast()
drop-shadow()
grayscale()
hue-totate()
invert()
opacity()
saturate()
sepia()
url()
Return a random number from 0 to n (inclusive) using Javascript.
Math.floor(Math.random() * (n + 1))
Return a random number from 1 to n (inclusive) using Javascript.
Math.floor(Math.random() * n) + 1
Return a random number from 0 to n (excluding n) using Javascript.
Math.floor(Math.random() * n)
Return a random number from m to n (inclusive) using Javascript.
Math.floor(Math.random() * (n - m + 1)) + m
Convert the Grinning Face Emoji’s Unicode number (U+1F600) into an HTML entity DECIMAL code.
Hint: 1f600 hex = 128512 integer
😀
& # 1 2 8 5 1 2 ;
Convert the Grinning Face Emoji’s Unicode number (U+1F600) into an HTML entity HEX code.
Hint: 1f600 hex = 128512 integer
😀
& # x 1 f 6 0 0 ;
ALT codes without leading zeroes (ALT nnn) produce characters & symbols based on IBM Code Page 437 / DOS (codes 0 - 255)
Note: Most do not correlate with their Unicode hex value
reminder
ALT codes with leading zeroes (ALT 0nnn) produce characters & symbols based on Windows Code Page 1252 (codes 01 - 0255)
Note: The decimal code can be derived from their Unicode hex value
Note2: These are a strict superset of ASCII wherein the first 128 codes are ASCII
reminder
Convert the Grinning Face Emoji’s Unicode number (U+1F600) into a CSS string escape value.
ie
.someClass {
content: ‘emoji here’
}
/1f600
Website for Emoji codes
emojipedia.org
VS Code Extention to lookup and insert emojis in their single character format using intellisence.
ie
:emojiName
Emoji Snippets
VS Code Extention to lookup and insert an emoji’s encoded string according to the current file’s language type.
ie
ji:emojiName
Emoji Code
Windows shortcut key to open Emoji Picker
Win + period(.) or Win + semicolon(;)
Given the below functions in a single file, how can you export all of them with the ‘helpful’ function being a default, in TWO lines of code.
const helpful = () =\> some code const sayHello = () =\> some code const listFoods = () =\> some code
export default helpful
export {sayHello, listFoods}
Given the below export declaration in the “./test.js” file. How would you import all of its functions?
export default helpful
export {sayHello, listFoods}
import helpful, {sayHello, listFoods} from ‘./test’
What does ‘000045’.slice(-3) return?
‘045’
const randNum = Math.floor(Math.random() \* 1000) Use the .slice() array function and string litteral notation to return the random number as a string padded with zeros (ie '004' or '051')
00${randNum}
.slice(-3)
\00765.slice(-3) -> ‘765’
\004.slice(-) -> ‘004’
A way to declare default props on a Class or Function based component.
Call FuncOrClassName.defaultProps = { …someProps } before exporting.
POJO stands for?
Plain Old Javascript Object
setState() (class based version) with function callback that takes two params.
setState((prevState, props) =\> { //some code return newStateObject //the new object only needs to contain the //updated properties } )
when using ‘this’ INSIDE of a function defined inside of a Class, the caller that later executes the function, loses the ‘this’ reference to the class (‘this’ becomes undefined, instead of pointing to class instance).
You can use the following to fix the reference to this:
1. in the class constructor:
this.someFunction = this.someFunction.bind(this)
2. when executing/when called:
call-> this.someFunction.bind(this)()
3. use an arrow function to define the function or execute the function within an arrow function
reminder
The arrow function binds ‘this’ to context of the object it was defined in, rather than the context of the object it’s called on.
reminder
Command to install FontAwesome Pro
npm install @fortawesom/fontawesome-pro
Command to install FontAwesome Free
npm install @fortawesom/fontawesome-free
In order to use FontAwesome PRO globally, what two npm commands need to be run?
npm config set “@fortawesome:registry” https://fontawesome.com/
npm config set “//npm.fontawesome.com/:_authToken” myProTokenId
Filename to create in a project to use FontAwesome PRO, locally.
.npmrc
What should be added into an local .npmrc to use FontAwesome Pro locally
@fortawesome:registry=https://npm.fontawesome.com/ //npm.fontawesome.com/:\_authToken=MyProAuthToken
Import statement to include FontAwesome PRO
import ‘@fortawesome/fontawesome-pro/js/all’
What are 4 special CSS properties to style the color and opacity of Duo-tone FontAwesome icons
- -fa-primary-color
- -fa-primary-opacity
- -fa-secondary-color
- -fa-secondary-opacity
Class name to reverse the primary and secondary opacity for a FontAwesome Duotone icon?
fa-swap-opacity
With FontAwesome you need to import css instead of js when you need to dynamically change which icon is used via className.
This is because the JS file generates and inserts an SVG. You rendered SVG doesn’t change based on className. An it seems the script that generates the SVG is compile time.
The CSS version of FontAwesome inserts a Unicode character which is inserted via the CSS class name. So you can dynamically swap out the icon via class name.
reminder
CSS property and value (property: value;) to make a square element circular.
border-radius: 50%;
A simple Math.random function/equations that returns True 25% of the time.
Math.random() < .25
A simple Math.random function/equations that returns True 72% of the time.
Math.random() < .72
A simple Math.random function/equations that returns false 65% of the time.
Math.random() >= .65
CSS property: value to give only the bottom right of an element a 10px radius.
border-radius: 0 0 10px 0;
CSS property: value to give only the top left of an element a 15px radius.
border-radius: 15px 0 0 0;
A function to control multiple input fields with one handler. (controlled inputs)
This pattern requires that each input field in the group have a matching name property as the value field in the state object.
ie (reusing the same handler on mulple form inputs)
const [formState, setFormState] = useState({
name1: value1,
name2: value2,
name3: value3,
…})
const handler = e =\> { setFormState(prev =\> { {...prev, [e.target.name]:e.target.value } }) }
In the below statement, [e.target.name] is called a ___.
{[e.target.name]: e.target.value}
Computed Property
On initialization of a component, component code seems to be run twice, even though the return/render only runs once.
values generated on the first execution of component code are used in the return/render. but values from the second run are received inside the subcomponents.
this won’t matter for static initial values, but dynamically generated values should be initialized outside of the component. ie v4() or Math.random()
Tried useRef and generating values in separate function. Neither work. UseState does not preserve the first generated value either.
reminder
When updating state using an array of objects and needing to edit a single object’s values, what pattern should be used to copy the prevState for editing.
Note: this pattern is used instead of spreading the array, because the objects would be copied over by reference. AKA the arrays would be separate and unique but the objects and values inside would be tied together between the arrays.
const copyPrev = prevState.map(obj => ({…obj}))
set a gradient background going from bottom left to top right with colors red, green, then white. Place it an element good for applying the style site wide
body {
background: linear-gradient(45deg, red, green, white);
}
Can the linear-gradient css method be used with the properties background, background-color, or both?
background
The Map object holds key-value pairs and remembers the original insertion order of the keys. Any value (both objects and primitive values) may be used as either a key or a value.
reminder
const map1 = new Map();
map1. set(‘a’, 1);
map1. set(‘b’, 2);
map1. set(‘c’, 3);
What does map1.get(‘b’) return?
2
How can you take an object parameter with unknown prop-name/value pairs, and assign them to the instance of the class in one line of code?
constructor(paramObj){ //line of code }
Object.assign(this, paramObj)
Use the Map() object to create a set called letterMap that tallies a count of each character in the following string. const ABA=’abacadabagoose’
const letterMap = new Map() for (let ltr of ABA) { letterMap.set(ltr, (letterMap.get(ltr) || 0) + 1) }
You can conditionally set a function to an event property in react. This is a good way to remove or add events based on some condition.
ie Do Something
Reminder
You can pass a call back to setState() as a SECOND parameter, which will be run AFTER the new state is set.
i.e. setState({someStateProp: newStateValue}, execACallbackAfter)
OR
i.e. setState((prevSt, props) => { return newState}, execACallbackAfter)
Reminder
list the three things that can cause a component to rerender.
setState() is called.
New prop value is received.
forceUpdate is called
List the class based life cycle methods.
componentDidMount()
componentDidUpdate(prevProps, prevState)
componentWillUnmount()
For React, when setting a height relative to the body, don’t forget that there is a root element between the body and app component.
Reminder
When using flex-direction of column, the containing element should have a height. Otherwise, thier is no space between the element to allow for arranging items in the vertical direction.
Reminder
One line of code to return a random float from -45 to +45 (not inclusive).
only use Math.random() once.
Math.random() * 90 - 45
One line of code to return a random float from -30 to +50 (not inclusive).
only use Math.random() once.
Math.random() * 80 - 30
How can you make a box-shadow extend inward toward the center and behind an element, instead of radiating outward
add inset in the css value/definition.
When using gsap animations on events, I should use the play, pause, reset, reverse methods instead of recalling the initial method. This should prevent the weird behavior I get when calling the gsap animation multiple times.
Reminder. (not yet proven)
Custom Array sorting:
arr.sort((a, b) => someFunction())
if someFunction returns a value < 0 a sorts before b
if someFunction returns a value > 0 b sorts before a
if someFunction returns a value of 0 the sort stays the same.
Reminder
const arr = [0, 5, 1, 10, 99, 2, -2, 75, 6, 7, 8] sort the above array in numeric order from largest to smallest
arr.sort((a, b) => b - a)
log out the below fruit names, in order of count, descending.
const arr = [ {fruit: 'pear', cnt: 99}, { fruit: 'apple', cnt: 52 }, {fruit: 'orange', cnt: 1}, {fruit: 'Watermelon', cnt: 10}, {fruit: 'banana', cnt: 8}, {fruit: 'grape fruit', cnt: 0}, {fruit: 'peach', cnt: 2} ]
arr. sort((a, b) => b.cnt - a.cnt)
arr. forEach(f => console.log(f.fruit))
log out the below fruit names, in order of name, descending.
const arr = [ {fruit: 'pear', cnt: 99}, { fruit: 'apple', cnt: 52 }, {fruit: 'orange', cnt: 1}, {fruit: 'watermelon', cnt: 10}, {fruit: 'banana', cnt: 8}, {fruit: 'grape fruit', cnt: 0}, {fruit: 'peach', cnt: 2} ]
arr.sort((a,b) =\> { // if a normally comes before b (a **b.fruit) return -1 return 0 })
arr.forEach(f => console.log(f.fruit))**
const testObj = {prop1: ‘test’, cnt: 5}
1 Save the above object to local storage
2 Retrieve the object from local storage and assign it to a newVar as an object.
localStorage.setItem(‘testObj’, JSON.stringify(testObj))
const newVar = JSON.parse(localStorage.getItem(‘testObj’))
What are 3 initial steps to adding React Router?
- npm install react-router-dom
- import {BrowserRouter} from ‘react-router-dom’
- Wrap component with in index.js
What React Router component is used to allow only the first matching route in a list of routes to be returned.
Write a basic React Route that matches the root path only and returns a component called Home.
Write a basic React Route that would always return an About component no matter what path it’s compared to.
Use a React Router component that allow the navigation from the current path to a new path of /newpath/somewhere
What is the difference between NavLink and Link
NavLink allows you to pass a special property called activeClassName
What does the activeClassName property do for the NavLink component?
When the NavLink is clicked ALL rendered NavLinks that match it’s “to” path will dynamically receive the className specified in the property, which is useful for dynamic styling.
Note: Can use the “exact” property in the NavLink to prevent partial matches on multiple NavLink “to” paths.
Write a basic React Route that matches the root path only and returns a component called About that needs a prop of userName=”Test User Jr”.
test
What is the major reason for using the render prop instead of the component prop for passing components with props into the Route component.
example:
VS
component will cause the component to unmount and reinstantiated every time a path is matched (aka every time a a matching link is clicked), as where render will follow normal life cycle if a matching path is re-entered (aka, it may rerender by it won’t be unmounted and reinstantiated)
What are the three props that are passed into a Route’s component/render function?
history, location, match
What are the four properties found in the Router’s component/render function’s match property?
isExact, params, path, url
withRouter allows you to receive the history prop from react-router-dom, when the component is not from a Route component. You need to encapsulate the component with withRouter in it’s export statement.
Reminider
1.
Immediately redirects you to a new path. Elements after this component don’t get rendered and the route that pushed you to the Redirect is not saved to history (aka, you cant get back to it)
- props.history.push(somePath)
Adds a new path to the history and updates the URL. Allows you to back into the page/url that got you to the push statement.
3 props.history.goBack()
Will take you back to the previous route stored in history
Reminder
CSS property/value to set the background to a gradient?
going from left to right
angled 25degs to the right, off the vertical
the first 10 percent solid white
10% to 75% grade from white to red
75% to 90% grade from red to green
90% to 100% solid green
background: linear-gradient(
115deg,
white 0 10%,
red 75%,
green 90% 100%
)
React router dom v6: List 7 commonly used named components
BrouserRouter
Navigate
Link
NavLink
Routes
Route
Outlet
React-router-dom v6: List the following hooks.
Provides a function to traverse browser history (redirect URL).
Provides an object to access and update the URL query params.
Provides an object with access to param values.
useNavigate()
useSearchParams()
useParams()
ES7 React/Redux/GraphQL/React-Native snippets shortcut to insert a functional component with export using arrow functions
_rafce
ES7 React/Redux/GraphQL/React-Native snippets shortcut to insert a functional component with export and propTypes using arrow functions
_rafcp
What property do you use on a NavLink to prevent the isActive from being triggered when one of its child paths is active?
end=true OR just pass end
React Router Dom v6: In the ‘to’ property for Link, NavLink, Navigate components, you can specify an integer to direct it to jump forward or backward through browser history.
reminder
A function that takes a function as an argument, returns a function, or both?
Higher-Order function
A technique used to convert a function that takes multiple inputs to one that takes fewer (ie one or none) inputs by returning a function that takes the secondary input. You could then pass and execute the function as a callback since it will return a new function definition.
Currying
Review Code-with-mosh Redux Video #7 “Currying” for great example.
const add = (a, b, c) => a + b + c
Rewrite the above function with the Currying technique so that it can be passed into the below as a parameter.
const addMore = (addFunc, someVal) => addFunc() + someVal
The problem that you’re trying to solve is the fact that addMore does not provide any values for the add function which you’ll be passing to addMore.
const add = (a,b,c) => ( ) => a + b + c
Now running add(2,4,6) returns a new function of ( ) => 2 + 4 + 6
A function that when the same values are passed in, it will always return the same result.
ie const someFunc = (a, b) => a * b
someFunc(3, 2) will always return 6
Pure Function
Copying an object using the spread operator (ie {…someObj}) results in a shallow copy, meaning that nested objects are still copied by reference.
You can copy the nested objects by overwriting their properties with another spread operator.
ie { …someObject, someSubObj: {…someObject.someSubObj}}
OR
You could copy using JSON.parse(JSON.stringify(someObject))
OR
Use a third party library like immer
reminder
What are the three building blocks of a Redux application?
Action
Store
Reducer
A Redux Action can be thought of as an event
A Redux Store can be thought of as a giant state object
A Redux reducer can be thought of as an event handler (a PURE function that updates the store state when an event happens)
reminder
What are 4 steps to follow when building a Redux application?
Design the store
Define the actions
Create reducers
Setup the store (based on reducers)
Given a single reducer exported by default from a file ‘./reducer’, write 4 lines of code to create a Redux store using the reducer and export it by default.
import {createStore } from ‘redux’
import reducer from ‘./reducer’
const store = createStore(reducer)
export default store
The Redux store object is composed of 5 properties (all methods). With one being Symbol(observable), what are the other 4 along with the params they accept?
dispatch(action)
subscribe(listener)
getState()
replaceReducer(nextReducer)
What does the command pwd stand for?
Print working directory
What is the below array function?
Takes a function that loops though each element, returns false and exits the loop if any of the functions returns false, otherwise returns true
.every()