JavaScript Simplified · One concept, one day, one project · Day 1 of 32
JavaScript and How It Works
What JavaScript is, where it runs, and how to make it say something. Then you write your first program: a short introduction, printed in the browser console.
By the end of today you can
- Say in plain words what JavaScript is and what it is for
- Tell JavaScript, HTML and CSS apart by the job each one does
- Add JavaScript to a page with
<script>and read the console - Write statements and comments, and run your first program
A web page has three languages working together. HTML is the content, CSS is the look, and JavaScript is the behaviour: the part that makes a page do something when you click, type, or scroll. This course is about that third language, taken slowly.
The plan for every single day is the same, so you always know what you are getting: one concept, one small project. Today the concept is what JavaScript is and how it runs, and the project is a short program that introduces you in the browser console.
1. What JavaScript Is
Definition
JavaScript is a programming language that runs inside the web browser. It is the language that lets a page react: show a message, change a colour, add an item to a list, send a form.
Real-Life Scenario
Think of a light switch on a wall. The wall is the HTML (it is there, it holds the switch). The paint is the CSS (how the wall looks). JavaScript is the wiring behind the switch: the thing that makes something happen when you flip it. Without it, the switch is just a shape on the wall.
JavaScript, HTML and CSS: three jobs
| Language | Its job | A sentence |
|---|---|---|
| HTML | The content and structure | Here is a heading, a paragraph, a button |
| CSS | The look | Make the button blue with rounded corners |
| JavaScript | The behaviour | When the button is clicked, show a message |
2. The Browser and the Console
Definition
The browser (Chrome, Firefox, Edge) has a JavaScript engine built in: software that reads your JavaScript and runs it. It also has a console, a small window where JavaScript can print messages and where you can see errors. It is the first place a developer looks.
You print to the console with console.log(...). Whatever you put in the brackets is shown.
console.log prints whatever is inside its brackets. This is how your program speaks to you while you build it.To see this in a real browser: open any web page, press F12 (or right click and choose Inspect), and click the Console tab. Anything your JavaScript logs appears there.
3. Adding JavaScript to a Page
The <script> tag
JavaScript lives inside a <script> tag in your HTML, usually just before the closing </body>. The browser reads the page top to bottom, so putting the script at the end means the HTML is already there when your JavaScript runs.
<script> tag sits in a page.4. Statements and Comments
Statements
A statement is one instruction. JavaScript runs them one after another, top to bottom. Each statement usually ends with a semicolon (;).
Comments
A comment is a note for humans that JavaScript ignores. You write one with two slashes (//) for a single line. Comments explain why, so your code makes sense later.
Today’s Mini Project
🧪 Console Introduction Program
Write a short program that introduces you in the console: your name, what you are learning, and one thing you are excited about. It is only a few lines, but it is a real program you wrote and ran.
Add two more lines to your introduction: the town you are in, and one app you use every day that you would love to understand. Expected: five lines in the console, all yours.
Open any website, press F12, click Console, type console.log("I was here") and press Enter.
Expected: your message appears in the console. You just ran JavaScript in a real browser.
You are looking at a web page. Most people see a finished thing. You are starting to see three layers stacked together: the content, the paint, and the wiring. From now on you are learning the wiring.
Checkpoint
What is the job of JavaScript on a web page?
Behaviour: making the page do something in response to the user, like reacting to a click, changing content, or sending a form. HTML is the content, CSS is the look, JavaScript is the behaviour.
What does console.log do?
It prints a message to the browser console. It is how your program speaks to you while you build, and the first tool you use to see what your code is doing.
Why does the <script> tag usually go at the end of the body?
Because the browser reads the page top to bottom. Putting the script last means the HTML is already on the page when the JavaScript runs, so it can work with it.
Tick Before You Move On
- ☐ I can say what JavaScript is for in one sentence
- ☐ I can tell HTML, CSS and JavaScript apart by their jobs
- ☐ I can print a message with console.log and find it in the console
- ☐ I wrote and ran my Console Introduction Program
Quick Recap
JavaScript is the behaviour of a web page: it makes things happen. It runs in the browser, which has a console where messages and errors appear. console.log prints to that console, and it is your first debugging tool. Code is a list of statements, run top to bottom; comments are notes JavaScript ignores.
Next: Day 2. A program that only prints fixed words is not very useful. Tomorrow you learn variables, so your program can remember information and work with it.