🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·🇬🇧 Limited Time — UK Only·🎓 Free Learning for 1 Month·🤖 Free AI Training Included·📚 4,000+ Lessons · 35,000+ Quizzes·🏆 GCSE Mocks · Olympiad Papers·⚡ Selected Students Only · Limited Places·🎁 Free Value Worth £2,000·
Free Course

JavaScript

The language of the web. Build interactive websites, games and apps that run in any browser.

21 Lessonsbeginner

Lessons

1

What is Programming

Programming is giving the computer step-by-step instructions. We write code in a language like JavaScript so the computer can run it. Browsers understand JavaScript and can run it on web pages.

JavaScript was created in 10 days in 1995 — and is now the most-used language in the worldDespite the name, JavaScript is completely unrelated to JavaStatements end with <code>;</code> (optional but good practice)
2

Variables

Variables store values. In JavaScript we use let or const. Use const when the value won't change, let when it might.

JavaScript uses <code>+</code> to join strings: <code>"Hello " + name</code>Template literals (backticks) are cleaner: <code>`Hello ${name}!`</code><code>typeof x</code> tells you the type of a variable
3

Data Types

JavaScript has numbers, strings (text in quotes), and booleans (true/false). You don't declare the type; JavaScript figures it out.

<code>typeof null</code> returns <code>'object'</code> — this is a famous JavaScript bug kept for historical reasons<strong>Falsy values</strong>: <code>0</code>, <code>''</code>, <code>null</code>, <code>undefined</code>, <code>NaN</code>, <code>false</code> — all evaluate to false in conditions<code>NaN</code> (Not a Number) is actually of type <code>number</code> — <code>typeof NaN === 'number'</code>
4

Conditions (if/else)

📚 What are conditions in JavaScript? They let your script **branch**: run one path when something is true, another when it is false. Use `if`, `else if`, and `else` with conditions in parentheses.

<strong>Truthy/falsy:</strong> <code>0</code>, <code>""</code>, <code>null</code>, <code>undefined</code>, <code>NaN</code> are all falsy in JS — treated as False in conditionsThe <code>!</code> operator negates: <code>if (!isLoggedIn)</code> means 'if not logged in'<code>switch (value) { case x: ... }</code> — useful for many possible values
5

Loops

📚 What are loops in JavaScript? They repeat a block of code. A classic `for` loop looks like `for (let i = 0; i < n; i++)` and runs a counted number of times. You can also loop arrays with `for...of` or use `while` when you want to keep going until something changes.

<code>break</code> exits any loop; <code>continue</code> skips to the next iteration<code>array.map(fn)</code> loops and returns a new array — used constantly in React<code>array.filter(fn)</code> loops and returns items where fn returns true
6

Functions

📚 What are Functions in JavaScript? A function is a named, reusable block of code. JavaScript has two main syntaxes: function greet(name) {} (declaration) and const greet = (name) => {} (arrow function). Call them by name as many times as you need, passing different inputs each time.

Function declarations are <strong>hoisted</strong> — you can call them before they're defined in the fileArrow functions and expressions are <em>not</em> hoisted — define them before calling<code>return</code> is implied when there's no <code>{}</code> in an arrow function
7

Arrays / Lists

📚 What are Arrays in JavaScript? An array is an ordered list of values in a single variable. You access items by their index (starting at 0). JavaScript arrays are dynamic - they grow and shrink as needed. They can hold any mix of types and come with dozens of built-in methods.

Arrays are <strong>objects</strong> in JavaScript — you can add non-numeric properties (but don't)<code>Array.isArray(value)</code> is the reliable way to check if something is an arrayModern array methods (<code>.map()</code>, <code>.filter()</code>, <code>.reduce()</code>) return new arrays and are preferred over mutation
8

Objects / Dictionaries

📚 What are Objects in JavaScript? A JavaScript object groups related data and functions together using key-value pairs. Keys (properties) are names; values can be anything: strings, numbers, arrays, even other objects or functions (called methods). Objects model real-world things naturally.

Arrays are objects — <code>typeof []</code> returns <code>'object'</code><strong>Destructuring</strong>: <code>const { name, age } = user</code> extracts properties into variables<strong>Shorthand</strong>: if variable and key share a name — <code>{ name }</code> instead of <code>{ name: name }</code>
9

Debugging Basics

📚 What is JavaScript Debugging? Debugging in JavaScript means finding and fixing errors in your code. Browser DevTools is your best friend: open with F12 (or right-click > Inspect), find the Console tab, and you see all console.log() output, error messages, and stack traces.

The most common JS errors: <code>TypeError</code> (wrong type), <code>ReferenceError</code> (undefined variable), <code>SyntaxError</code> (typo in code)Chrome DevTools has a <strong>network tab</strong> showing every API request — invaluable for fetch debuggingYou can run JS directly in the Console: type any expression and press Enter
10

String Methods

📚 What are JavaScript String Methods? JavaScript strings come packed with built-in methods for transforming, searching, and extracting text. Like Python, JS strings are immutable: methods always return a new string. Chain multiple methods together for powerful one-line transformations.

Strings in JS are sequences of UTF-16 code units — emoji can be 2 units, making <code>.length</code> surprising<code>.at(-1)</code> is the modern way to get the last character (cleaner than <code>[str.length-1]</code>)Regular expressions unlock powerful pattern matching — <code>/\d+/g</code> matches all digit sequences
11

Try and Catch

📚 What is Try/Catch in JavaScript? try/catch lets your JavaScript code handle errors gracefully. The code inside try runs normally. If anything throws an error, execution jumps to the catch block instead of crashing with an uncaught exception. The error object e has .message and .stack properties.

Unhandled promise rejections in async code used to silently disappear — always <code>catch</code> async errorsYou can throw any value: <code>throw 'error message'</code>, but throwing an <code>Error</code> object is best practice<code>window.onerror</code> and <code>window.addEventListener('unhandledrejection')</code> catch global errors for logging
12

map() and filter()

📚 What are map() and filter()? map() and filter() are the two most important array methods. map() transforms every item in an array, returning a new array of the same length. filter() keeps only the items where a condition is true. Both take a callback function and never change the original array.

<code>.map()</code> always returns an array of the same length; <code>.filter()</code> may return a shorter oneBoth accept a second argument: <code>callback(item, index, array)</code>For transforming AND filtering together, <code>.flatMap()</code> can do both in one pass
13

Spread and Rest operators

📚 What are Spread and Rest? The ... operator does two different but related things. As spread, it expands an array or object: [...arr] creates a shallow copy, {...obj} merges objects. As rest, it collects remaining arguments into an array: function f(...args) accepts any number of arguments.

Spread creates a <strong>shallow copy</strong> — changing nested objects still affects the originalFor deep cloning use <code>structuredClone(obj)</code> (modern) or <code>JSON.parse(JSON.stringify(obj))</code> (older trick)Rest must always be the <strong>last parameter</strong>: <code>function (a, b, ...rest)</code> is valid, but <code>(...rest, a)</code> is not
14

Destructuring

📚 What is Destructuring? Destructuring is a clean way to extract values from arrays and objects into separate variables. Instead of const name = user.name; const age = user.age; you write const { name, age } = user; in one line. It makes code shorter and more expressive.

Destructuring is purely <strong>syntactic sugar</strong> — it compiles to the same old property access under the hoodReact's <code>useState</code>, <code>useReducer</code>, and custom hooks all return arrays designed for destructuringYou can destructure function return values inline: <code>const { width, height } = getSize();</code>
15

JSON

📚 What is JSON? JSON (JavaScript Object Notation) is the universal language of data on the web. When your app talks to an API, data travels as a JSON string. JSON.stringify() converts a JavaScript object into a JSON string for sending. JSON.parse() converts it back into an object after receiving.

JSON was invented by Douglas Crockford in the early 2000s and is now used by virtually every web API<code>JSON.stringify()</code> skips <code>undefined</code> values and functions — they simply disappearA <code>Date</code> object stringifies to an ISO string: <code>"2025-01-15T10:30:00.000Z"</code>
16

Fetch and async/await

📚 What is Fetch? fetch() is the modern browser API for making HTTP requests to servers and APIs. It returns a Promise, so you use async/await to handle the result cleanly. fetch() is how JavaScript apps talk to the web: loading data, submitting forms, calling AI APIs.

Fetch is built into all modern browsers — no library neededUnlike older <code>XMLHttpRequest</code>, Fetch uses Promises and is far cleanerCORS (Cross-Origin Resource Sharing) can block fetch requests — the server must allow your domain
17

Classes

📚 What are JavaScript Classes? A class is a blueprint for creating objects. You define properties and methods once in the class, then create as many instances as you need with new. Classes organise related data and behaviour together, making complex code much easier to manage.

JavaScript classes were added in ES6 (2015) — before that, developers used constructor functions manuallyUnder the hood, classes use the <strong>prototype chain</strong> — <code>class</code> is syntactic sugar<code>instanceof</code> checks: <code>rex instanceof Dog</code> → <code>true</code>
18

Modules (import/export)

📚 What are ES Modules? ES Modules let you split your JavaScript into separate files and share code between them. export makes a value available to other files. import loads it. Modern JavaScript apps (React, Vue, Node.js) are built entirely with modules - each file is its own module.

ES Modules are <strong>static</strong> — all imports are resolved at parse time, enabling tree-shaking (removing unused code)You can have <strong>only one</strong> default export per file, but unlimited named exportsBefore ESM, JavaScript used CommonJS (<code>require/module.exports</code>) — still used in Node.js projects
19

reduce()

📚 What is reduce()? reduce() is the most powerful array method. It processes every item in an array and builds a single result - it can be a number, string, object, or even another array. The callback receives an accumulator (the running result) and the current item, and returns the next accumulat…

reduce is the most powerful array method — map and filter can both be implemented with reduceAlways provide an initialValue to avoid bugs on empty arraysreduceRight() runs from right to left
20

setTimeout and setInterval

📚 What are setTimeout and setInterval? setTimeout() schedules a function to run once after a delay (in milliseconds). setInterval() schedules a function to repeat every N milliseconds until cleared. Both are essential for animations, countdowns, polling, and any time-based behaviour.

21

Template Literals

📚 What are Template Literals? Template literals are strings wrapped in backticks (`) instead of quotes. Inside them, ${expression} is evaluated and embedded. They make string building much cleaner than concatenating with + signs, and support multi-line strings naturally.

Template literals were introduced in ES6 (2015) — before that, string concatenation was the only way<strong>styled-components</strong> and <strong>GraphQL</strong> use tagged template literals as their core syntaxThe browser doesn't parse HTML inside template literals — use a sanitiser to avoid XSS if inserting user content into HTML

Start learning JavaScript free today

AI tutoring · quizzes · projects · works on any device