JavaScript Tutorial
JavaScript is the programming language of the web. HTML gives a page its structure, CSS makes it look good, and JavaScript makes it do things: check quiz answers, compute a grade, show and hide menus, run a timer, or power a simple game.
This free course has 30 short lessons. Every lesson has examples you can edit and run right on the page, a list of common mistakes, a Taglish summary and a quick quiz. You don't need to install anything: your browser already runs JavaScript.
Before you start
You should know basic HTML and a little CSS. If you have never written a web page, take the HTML Tutorial first, at least up to Class and Id, because JavaScript often finds elements by their id or class.
What you'll be able to do
- Store information in variables and do math with it
- Make decisions with
ifand repeat work with loops - Write your own functions and reuse them
- Work with lists (arrays) and records (objects)
- Change a web page with the DOM and react to clicks and typing
- Build a grade calculator, a to-do list and a quiz game
All lessons
Getting Started
- Introduction to JavaScriptWhat JavaScript is, what it can do on a web page, and how it works together with HTML and CSS. Write and run your first line of JavaScript.
- Where to Put JavaScript — script Tags and External FilesAdd JavaScript inside a script tag in the head or body, or in a separate .js file. Learn why scripts usually go at the end of the body or use defer.
- JavaScript Output — console.log, textContent, innerHTML and alertFour ways JavaScript shows results — writing into an element with textContent or innerHTML, printing to the console, alert boxes, and document.write.
- JavaScript Syntax, Statements and CommentsThe basic grammar of JavaScript — statements, semicolons, code blocks, case sensitivity, naming rules and comments that explain your code.
Variables & Data
- JavaScript Variables — let, const and varStore values in variables with let and const, change them, and learn why modern JavaScript avoids var. Includes a baon budget example.
- JavaScript Data Types — Strings, Numbers, Booleans and MoreThe kinds of values JavaScript works with — string, number, boolean, undefined, null, plus arrays and objects — and how to check a type with typeof.
- JavaScript Operators — Arithmetic and AssignmentDo math in JavaScript with +, -, *, /, % and **, update variables with +=, -= and ++, and understand the order of operations.
- JavaScript Strings and Template LiteralsWork with text in JavaScript — quotes, escape characters, string length, joining text, and template literals with ${} for clean messages.
- JavaScript String MethodsUseful string methods — toUpperCase, toLowerCase, trim, includes, startsWith, indexOf, slice, replace, split and padStart — with school and store examples.
- JavaScript Numbers and the Math ObjectConvert text to numbers, round money with toFixed, use Math.round, floor, ceil, max, min and Math.random to make dice and random pickers.
Decisions & Loops
- JavaScript Comparisons and Logical OperatorsCompare values with ===, !==, >, <, >= and <=, combine conditions with && (and), || (or) and ! (not), and understand truthy and falsy values.
- JavaScript if, else and else ifMake your program decide what to do with if, else and else if. Build a DepEd-style grade descriptor and a simple login check, and learn the ternary operator.
- JavaScript switch StatementChoose between many exact values with switch, case, break and default — with a day-of-the-week schedule and a sari-sari store menu.
- JavaScript for LoopsRepeat code with for loops — count up and down, skip by steps, build multiplication tables, loop through strings and arrays, and use break and continue.
- JavaScript while and do…while LoopsRepeat code while a condition is true with while and do…while loops — savings goals, guessing games — and learn how to avoid infinite loops.
Functions
- JavaScript FunctionsWrite reusable blocks of code with functions — parameters, arguments, return values and default values — with a grade-average and peso-change calculator.
- JavaScript Scope and Arrow FunctionsUnderstand where variables can be used (global, function and block scope), and write short functions with arrow syntax and callbacks.
Arrays & Objects
- JavaScript ArraysStore lists of values in arrays — create them, read and change items by index, get the length, add and remove items with push, pop, shift, unshift and splice.
- JavaScript Array Methods — forEach, map, filter, find, reduce and sortProcess lists the modern way with forEach, map, filter, find, some, every, reduce and sort, using class grades and store prices as examples.
- JavaScript ObjectsGroup related data into objects with properties and methods — read, change, add and delete properties, loop through them, and store a whole class as an array of objects.
- JavaScript JSON — Saving and Sharing DataJSON is the standard text format for data on the web. Learn its rules, convert objects to text with JSON.stringify and back with JSON.parse.
The DOM
- The JavaScript HTML DOM — Finding ElementsThe DOM is how JavaScript sees your HTML page. Find elements with getElementById, querySelector and querySelectorAll, and understand the page as a tree.
- Changing HTML, Styles and Classes with JavaScriptChange text, HTML, attributes, styles and CSS classes with JavaScript, and create, add and remove elements with createElement, append and remove.
- JavaScript Events and addEventListenerReact to clicks, typing, mouse movement and key presses with addEventListener. Use the event object, preventDefault and event delegation.
- JavaScript Forms and Input ValidationRead values from inputs, selects, checkboxes and radio buttons, validate them with JavaScript, show friendly error messages, and build a BMI calculator.
Going Further
- JavaScript DatesWork with dates and times — create Date objects, get the year, month, day and time, format dates in Filipino and English, and compute ages and countdowns.
- JavaScript Timers — setTimeout and setIntervalRun code later with setTimeout and repeatedly with setInterval, stop timers with clearInterval, and build a live clock and a quiz countdown.
- JavaScript Errors and DebuggingRead error messages, find bugs with console.log and the browser DevTools, and handle problems gracefully with try, catch, finally and throw.
- JavaScript ClassesCreate many similar objects from one blueprint with class, constructor and methods, and extend a class with inheritance. Includes a bank-style savings account.
- JavaScript Final Project — Build a Quiz GamePut everything together and build a complete quiz game with questions stored in an array of objects, a score, a timer, feedback and a results screen.