JavaScript cheat sheet
Everything the course uses, on one page: the language basics, the drawing helpers and the usual game patterns — short enough to read between two runs.
Variables
let score = 0store a value you can changeconst W = 480a value that never changesscore = score + 1update a variablelet name = 'Ada'store text, called a stringLoops & conditions
if (score > 5) { … }run code only when it is truefor (let i = 0; i < 3; i++) { … }repeat three timesi = i + 1add one, also written i++while (hp > 0) { … }repeat while a condition holdsFunctions
function update(dt) { … }our loop, runs 60 times a secondburst(x, y)call a function you wrotereturn 42send a value back to the callerArrays
let list = [1, 2, 3]an ordered listlist.push(item)add to the endlist.pop()remove from the endlist[0]read the first itemlist.lengthhow many items are in itlist.filter(p => p.life > 0)keep only the items you wantDrawing in this course
clear('#101425')paint the whole canvasrect(x, y, w, h, color)draw a rectanglecircle(x, y, r, color)draw a circletext('Score: ' + score, 12, 24, '#fff')draw text on the canvasbeep(440, 60)play a tone: pitch, then millisecondsInput & time
keys.left · keys.spacea held key is truemouse.x · mouse.y · mouse.downpointer position and pressdtseconds since the last frameGame patterns
x = x + vx * dtmove with speed × timeif (x < 0 || x > 480) vx = -vxbounce off the wallsstate = 'won'switch between game statesMath.random()a random number from 0 up to 1Math.floor(Math.random() * 10)a random whole number 0–9Keep this page open in a second tab while you code — or print it and stick it next to the screen. Every rule here is taught inside a lesson first; this is only the summary. Start free on the main page.