Professional Documents
Culture Documents
Freemote Dont Forget Js
Freemote Dont Forget Js
JavaScript
()
Js
{}
</
>
created by Aaron Jack
SLICE
SPLIT
JOIN
Convert an array to a string,
[“Jun”, “1”].join(“-“) separated by character you
provide (or nothing using
empty string)
returns “Jun-1”
SPLICE
Modifies the array in place by
removing 2nd arg # of items at
[4, 2, 3].splice(0, 1) index of first arg. You can also
add items with a third argument.
returns [4] Finally, returns removed items
original array is set to [2, 3]
Arrow Functions
Replace the function keyword with => after your arguments
and you have an arrow function.
ARROW FUNCTION DECLARATION
AUTO RETURNS I
AUTO RETURNS II
SINGLE PARAMETER
If you just have a single
word => word.toUpperCase() parameter, you don’t need the
parentheses around your
params
Objects
Powerful, quick storage and retrieval
KEY LITERALS
OBJECT.KEYS
DESTRUCTURING
DESTRUCTURING II
Array Methods
These methods ALSO create copies of the original
(except for sort)
MAP
FOREACH
FILTER
Runs function once per item,
[1, 2, 3].filter(n => n > 1) if false, the item will not be
ncluded in the new array, if
true, it will
returns [2, 3]
REDUCE
Runs function once per item,
your return value becomes the
[1, 2, 3].reduce((a,val) => a + val) accumulator arg on the next
iteration. The accumulator starts
at 0 by default but you can
change it with an optional 2nd arg.
returns 6
SORT
Sorts array in place, by default
in ascending numerical (or
alphabetical) order. Passing in a
[3, 1, 2].sort() 2 argument comparison function
(optional) can arrange items in a
descending, or custom order
returns [1, 2, 3]
the DOM
For every HTML tag there is a JavaScript DOM node
CREATE ELEMENT
SET STYLE
ADD CLASS
INNER HTML
ADD CHILD
QUERY SELECTOR
QUERY SELECTOR A LL
Async Programming
Usually network requests, these functions happen outside of
the normal “flow” of code
FETCH
PROMISE.THEN
.THEN CHAINING
PROMISE.CATCH
PROMISE.ALL
You can pass multiple promises
Promise.all([fetch(...),fetch(...)] into the Promise.all function.
Attaching a .then block will give
then(allResults => ...) you the result of all the promises,
in a single array.
ASYNC / AWAIT I
Async await is a cleaner syntax
for promises, instead of .then
const res = await fetch(URL) blocks simply use the await
keyword, which will block your
code until the promise returns
..however...
ASYNC / AWAIT II
Await keywords must be inside
of an “async” function -- simply
const getURL = async (URL) => ( attach the async keyword before
await fetch(URL) any function, or arrow function
definition
@aaronjack @coding_with_jan
The Freelance Developer Bootcamp