Skip to content
VJ Classes

One place to learn science, commerce, arts, computers and life skills

8 lessons summarised. Read it before an exam, or print it.

JavaScript basics

How JavaScript runs

Key points

  • JavaScript runs in every browser’s engine, and on servers with Node.js.
  • The console (F12) is the quickest place to experiment.
  • Load scripts at the end of the body or with defer.
  • Read error messages: they tell you the problem and the line.

Variables and types

Key points

  • Use const by default, let when the value must change; avoid var.
  • Main types: string, number, boolean, undefined, null and object.
  • Template literals (backticks) embed values in strings.
  • Convert form input with Number(); compare with ===.

Conditions and loops

Key points

  • if / else if / else runs the first matching branch; combine conditions with &&, || and !.
  • Falsy values: false, 0, “”, null, undefined, NaN.
  • for loops for counts, while loops for conditions, for…of for lists.
  • Avoid infinite loops; use break and continue with care.

Building blocks

Functions

Key points

  • Functions take parameters, run code and return values.
  • Default parameters and arrow functions make code shorter.
  • Variables inside a function are local to it (scope).
  • Functions are values: callbacks pass behaviour into other functions; keep each function to one job.

Arrays and objects

Key points

  • Arrays are ordered lists (index from 0); objects hold named properties and methods.
  • Arrays of objects are the most common real-world data shape.
  • map, filter, find, reduce, sort and forEach handle most list work.
  • Destructuring and spread make copies and extract values; JSON converts data to and from text.

The DOM and events

Key points

  • The DOM is the page as objects; select with querySelector and querySelectorAll.
  • Change text with textContent (safer than innerHTML), and styles through CSS classes.
  • addEventListener responds to clicks, input, submit and more; preventDefault stops default actions.
  • Event delegation handles events for many (and future) child elements with one listener.

Projects

Project: a quiz game

Key points

  • Keep data (questions) separate from logic (functions).
  • Render with createElement and textContent; attach listeners as you create buttons.
  • Track state in variables (current question, score) and update the DOM from it.
  • Extend with shuffling, timers, restart and data loaded from JSON.

Project: a to-do list

Key points

  • Keep state in an array; one render function draws the page from it.
  • Save with localStorage (as JSON text), guarded by try…catch.
  • Use textContent for user text, and event delegation for list actions.
  • localStorage is per browser and device; never store sensitive data in it.

Important terms

  • arguments
  • arrays
  • async/await
  • Avoid side effects
  • Boolean
  • Break things on purpose
  • Build small projects
  • callback
  • camelCase
  • Change things
  • Comments
  • Console
  • DOM
  • ECMAScript
  • editing
  • error message
  • event delegation
  • Events
  • F12
  • false
  • fetch
  • filters
  • first
  • for
  • for…of
  • function
  • infinite loop
  • JavaScript engine
  • JSON
  • JSON file
  • Keep them short
  • localStorage
  • make decisions
  • methods
  • Naming rules
  • Node.js
  • null
  • Number
  • Object
  • One job per function
  • parameters
  • Persistence
  • remembers them
  • repeat
  • Restart
  • return value
  • Shuffle
  • state
  • State-driven rendering
  • statements
  • strict equality
  • String
  • text
  • timer
  • Type the examples yourself
  • undefined
  • variable
  • while
Enrol to read the full lessons. This page is a summary. The lessons explain every point with examples, and enrolling also gives you the full notes PDF and your progress. See the course