let <name> = <value> |
Declare variable |
let <name> = prompt("<text">) |
Prompt user for input |
+ |
Concat or add |
if (<condition>){<if true>} else {<if false>} |
Conditional |
<condition> ? <if true> : <if false> |
Conditional shorthand |
<variable>.trim() |
Trim whitespace |
let <objname> = {<name> : <value>, <name> : <value>} |
Create object with attributes |
|| |
Logical or |
<variable>.replace("<toreplace>","<replacewith>") |
Replace in string |
&& |
Logical and |
<variable>.toUpperCase() |
To uppercase |
let <name> = [<var1>,<var2>] |
Create list / Array |
listName[<index>] |
Access value in index position of array |
"<string> $(variable)" |
Literals, add value to string. Can concat too with +
|
listName[<index>] = <value> |
Update value in index position of array |
Math.round(<value>) |
Round number |
Math.floor(<number>) |
Round down |
Math.ceil(<number>) |
Round up |
Math.min(<num1>,<num2>) |
Lowest value provided |
Math.max(<num1>,<num2>) |
Highest value provided |
let <name> = Date() |
Current time |
<name>.getMinutes() |
Return value. Works for hours, date, day, month, year as well |
Date.parse("") |
Create date |
while (condition) {<stuff to do>} |
Loop while condition is true |
<name>.forEach(function(<name>) {<stuff to do} |
Do once for each item in list |
do {<stuff to do>} while(<condition>) |
Do while condition is true |
for (<initial>,<condition>,<increament>) {stuff to do} |
For loop while condition is true. Increamenet runs after each loop. |
function <name>(<things to bring in>) {<thing to do>} |
Create a callable function |
function <name>(<variable> = <default>) { } |
Provide a default value to variable if one isn't provided |
function <name>() {<thing to do> return <thing to give back>} |
Returns value |
let <name> = new <objName>() |
Create object instance |
<objName>.<variable> |
Call variable value inside object. New variables can be used to create new prop |
let <name> = [ {<objVar>:<objVal>},{<objVar>:<objVal>}] |
Array of objects |
for(let <var> in <obj>) {<thing to do>} |
Enumerate through object properties |
let <name> = document.querySelector(#"text") |
Applies to the below, returns element / name on page matching selector |
<name>.addEventListener("<listenerType>",<function>()) |
Execute function when <text>
is selected. Type can be click, mouseenter, mouseleave, mousedown, mouseup, mousemove, keydown, keyup |
let <name> = document.querySelectorAll(#"text") |
Returns all elements / name on page matching selector |
<form> <input type ="<type>" id="<name>" /> </form> <script> <function to do> </script> |
Create a form with function |
export <item> |
Export for use elsewhere |
Created By
Metadata
Comments
aeon, 20:09 20 Mar 23
Would love to see this fully built out!
Add a Comment
Related Cheat Sheets