Inspired by CS50 WebTrack
Thanks to w3schools
JavaScript is a programming language that runs in a web browser.
It can be embedded into HTML using the <script> tag to
add interactivity to a page — for example, showing or hiding content when a user makes a selection,
or validating a form before it is submitted.
JavaScript is an interpreted language, not a compiled one. Compiled code is machine dependent — it must be recompiled for different processors or architectures. An interpreter runs the high-level source code directly, making it machine independent. This matters for JavaScript because it is likely to run on a wide variety of devices with different hardware.
| Compiled | Interpreted (JavaScript) |
|---|---|
| Translated into machine code before running. | Translated and run line by line at runtime. |
| Fast to execute once compiled. | Slightly slower to execute. |
| Machine dependent — compiled code only works on the target architecture. | Machine independent — the same code runs on any device with a browser. |
| Errors found at compile time. | Errors found at runtime. |
You are expected to be able to follow and write basic JavaScript code. You do not need to memorise exact syntax — the exam will not penalise minor inaccuracies. You should understand the JavaScript equivalents of standard pseudocode structures (see the table below).
You will not be expected to use JavaScript for object-oriented programming or file handling.
There are three ways JavaScript can produce output that you need to know:
| Method | Code | Effect |
|---|---|---|
| Change an HTML element |
|
Updates the content of an element on the page. Most commonly used in exam questions. |
| Write to the document | |
Writes directly into the HTML page. |
| Alert box | |
Shows a pop-up message box in the browser. |
Input is taken by reading values from a form:
document.getElementById("fieldId").value.
You do not need to memorise this — exam questions will focus on what you do with the input once received.
| structure | description | code example |
|---|---|---|
document.getElementById() |
The key to linking JavaScript to your HTML. Given an element's id, it returns that
element as an object so JavaScript can read or change it.
Use .innerHTML to read or change the content of an element.Use .value to read input from a form field.This is how JavaScript interacts with the DOM (Document Object Model) — the browser's representation of the HTML page as objects that can be manipulated with code. |
|
| Variables / assignment |
Declare a variable with var or let and assign it a value with =.
Variables can hold numbers, strings, or booleans. You can change the value later by assigning again.
|
|
| if / else if / else |
Runs different blocks of code depending on a condition.
Use == to compare values, && for AND, || for OR,
and != for not equal.
Only the first true branch runs.
|
|
| for loop | Repeats a block of code a set number of times. The loop has three parts: a starting value, a condition to keep looping, and an update step. Use when you know in advance how many times to loop. |
|
| while loop | Repeats a block of code while a condition is true. Use when you don't know in advance how many times to loop. Make sure the condition can eventually become false, or the loop will run forever. |
|
| Functions |
A named, reusable block of code. Define it with function, then call it by name.
Functions can take parameters (inputs) and return a value.
In exam questions, you are often asked to complete a partially written function.
|
|
| Arrays |
An array stores multiple values in a single variable.
Items are accessed by their index, starting at 0.
Use .length to find how many items are in the array.
Arrays are often used with a for loop to process each item.
|
|