A web page is built from three layers. HTML is the structure (headings, paragraphs, images). CSS is the style (colours, layout). JavaScript is the behaviour: what happens when you click, type or scroll. Almost every website you use has JavaScript running in it.
Where to run it
You do not need to install anything. Every browser has a console: press F12 (or right-click, then Inspect) and open the Console tab. You can type JavaScript there and press Enter. Later we will put JavaScript inside a web page.
Your first program
console.log() prints a value. Text goes in quotes. Statements usually end with a semicolon ;.
console.log("Namaste, world!");
console.log("I am learning JavaScript");
Output:
Namaste, world!
I am learning JavaScript
Comments
// This is a comment: the browser ignores it
console.log("Hello"); // and so is this note
/* A longer note
over several lines */
Output:
Hello
Doing maths
console.log(5 + 3);
console.log(10 / 4);
console.log(2 * (3 + 4));
Output:
8
2.5
14
JavaScript is case sensitive:
console.logworks,Console.Logdoes not. If something fails, check spelling, quotes and brackets first.
Try it yourself
- Open your browser console and print your name.
- Calculate how many minutes are in a week.
- Break the code on purpose and read the error message in red.
Next lesson: storing values in variables.

Comments
Loading comments…