Interactive javascript cheatsheet
Type
/
to search
Basics
execute javascript from the browser console
execute javascript from an inline <script> tag
execute an external javascript script from html
execute javascript outside the browser using Node.js
console.log()
comments
variables
alert
undefined and null
good references
String
introduction
+
template string
escape characters
.length
.split()
.substring()
.charAt()
.toLowerCase()
.toUpperCase()
Number
introduction
arithmetic operations
increment and decrement assignment
from string
from boolean/undefined/null
parseInt()
parseFloat()
hexadecimal, binary and decimal exponential notations
.toString(): hexadecimal and binary representation strings
bitwise operations
NaN: Not-A-Number
.toLocaleString(): format a number separators (eg. decimal and thousand separators)
.toLocaleString(): format currency
Boolean
introduction
comparison operators (==, ===, !=, !==, >, >=, <, <=)
logical operators (&&, ||, !)
if, else if and else
while loops
do while loops
Array
introduction
access an array element
for loop: iterate over an array
.push(): add an item to the end of an array
.unshift(): add item to the start of an array
.pop(): remove last item
.shift(): remove first item
.slice(): get a slice of an array
.splice(): remove or replace existing elements and/or insert new ones
.filter(): create a filtered array
.map(): transform one array to another
.reduce(): iterate over array and accumulate over a value
.forEach(): iterate over elements of an array
.join(): join an array into a string
create an array filled with zeros
create an array filled with number from 0 to n-1
Function
introduction
function which receives inputs
function returns returns a value
arrow functions
function references
higher order function
recursion
.call(): call a function with another `this`
.apply(): call a function with another `this`
.bind(): create a new function with a bound `this`
Object
introduction
access an object's property
insert/modify an object's properties
remove an objects's property
method: a function property
this: reference other properties inside an method
Object.keys(): list an object's keys
Object.values(): list an object's values
Object.entries(): list an object's key-values pairs
prototype object
`new` keyword
Class
introduction
getter and setter
class field
bind `this` to the instance object
inheritance
static methods/properties
private methods/properties
instanceof
Date
introduction
from string
from year, month, day, hours, minutes and seconds
get year, month, day, weekday, hours, minutes, seconds, milliseconds and timestamp
from epoch timestamp
to formatted string
.toLocaleDateString(): more control over formatted string
to specific timezone
Errors
try...catch
throw
finally
custom errors
Promise
why we need them?
introduction
chaining
async/await
Promise.all()
Promise.allSettled()
error handling
Generator
introduction
combining generators
passing values to a generator
async generators