You click a button and a menu opens. You add a product to a cart and the total changes. You enter a password and a message tells you it is too short. JavaScript is often the code making those moments happen.
If you are starting web development, you do not need to learn a framework on day one. Start by understanding what JavaScript does, where it runs and how a few lines of code can change a page. This first lesson walks through those ideas with examples you can try.
What is a script?
A script is a set of instructions that a computer runs to carry out a task. Imagine checking the price of a notebook, multiplying it by the quantity and displaying the total. Written as JavaScript, that small task looks like this:
const price = 250;
const quantity = 3;
const total = price * quantity;
console.log(total);
The output is 750. Each line has a job: store a value, calculate a result or show it. These statements run in order. As you learn more, you will also write code that waits for a click or a response from a server.
So, what is JavaScript?
JavaScript is a programming language used to add behaviour to websites and build applications. In a browser, it can respond to a visitor, update page content and request information without reloading the whole page.
A useful way to understand its place is to look at the three technologies you will usually meet together:
| Technology | Its job | A button example |
|---|---|---|
| HTML | Structure and meaning | Creates the button |
| CSS | Appearance and layout | Sets its colour and spacing |
| JavaScript | Logic and interaction | Responds when you click |
HTML is a markup language and CSS is a style sheet language. They work alongside JavaScript, but they are not scripting languages.
Client side and server side
In the browser
Client-side code runs on the visitor’s device, usually in a browser such as Chrome, Firefox or Edge. JavaScript can open a navigation menu, filter a product list or show a helpful form message. These are interactions you can see as you use the page.
On the server
Server-side code runs on the system handling requests behind the website. It might check a login, read a database or save an order. PHP and Python are examples of languages used for this work. JavaScript can run here too, using a runtime such as Node.js.
The same language can therefore be used on both sides, but the tools available are different. Browser code works with the page; server code can work with server files and databases. A form may offer instant feedback in the browser, while the server must still validate what was submitted.
A little history, and a useful name
JavaScript began at Netscape in 1995, where Brendan Eich created its first version. Early naming included LiveScript before the language became known as JavaScript.
You will also hear the name ECMAScript. It is the language specification that defines JavaScript’s core rules and features. JavaScript engines implement those rules; browsers add APIs for things such as interacting with a document. You can learn to write your first programs without reading the specification.
Features you will meet as you practise
Some descriptions of JavaScript can sound complicated. Here is what a few of those terms mean in everyday programming:
- Dynamic typing: you do not have to declare a variable’s type in advance. A value can be a number, a string or another type.
- Functions: you can group instructions into a reusable task instead of writing them again.
- Objects: you can keep related information together, such as a student’s name and course.
- Prototype-based behaviour: objects can inherit behaviour from other objects. You will study this after the basics.
- C-style syntax: braces, parentheses and familiar operators help organise your instructions.
JavaScript is often described as interpreted, although modern engines also compile code while running it. In one execution context, a JavaScript thread processes one task at a time. Asynchronous operations help it handle waiting; workers can provide separate execution contexts. For your first lesson, concentrate on writing a short program you can explain.
Your first JavaScript program
Open your browser’s developer tools and choose the Console tab. Type this example yourself, then press Enter:
const studentName = "Ayesha";
function greetStudent(name) {
return "Welcome, " + name + "!";
}
console.log(greetStudent(studentName));
You should see Welcome, Ayesha!. Change the name and run it again. The function stays the same; the value you pass into it changes the greeting.
Try a small interaction
This button uses JavaScript to keep track of clicks. Try it, then look at the code beneath it.
Button clicks: 0
let clicks = 0;
const button = document.querySelector("#blog-demo-button");
const result = document.querySelector("#blog-demo-result");
button.addEventListener("click", function () {
clicks += 1;
result.textContent = "Button clicks: " + clicks;
});
The browser finds the button, listens for a click and runs the function when that event happens. If you try this code in your own HTML file, add elements with the matching IDs and load the script after those elements exist.
Built-in tools, libraries and frameworks
JavaScript includes useful building blocks. Arrays hold lists, strings hold text, dates represent dates and times, and regular expressions help match text patterns. The Math object provides calculations such as rounding.
const topics = ["HTML", "CSS", "JavaScript"];
const courseName = "javascript";
console.log(topics.length);
console.log(courseName.toUpperCase());
console.log(Math.round(4.6));
These lines print 3, JAVASCRIPT and 5. You do not need to memorise every built-in tool. Learn what a tool does, try a small example and look it up when you need it.
Names such as jQuery, React, Angular, Vue, Node.js and Express refer to different tools in the JavaScript ecosystem. They are not separate versions of JavaScript. For example, React helps build interfaces, Node.js runs JavaScript outside the browser, and Express helps build server applications with Node.js.
Continue with JavaScript variables explained with simple examples, then practise changing values yourself.
Is JavaScript the same as Java?
No. Java and JavaScript are different programming languages. Their names can confuse new learners, but learning Java is not a prerequisite for learning JavaScript.
For now, practise variables, conditions, loops and functions. Then use those skills to update a page and handle events. A small program that you can read, change and explain is a useful first achievement.
Your five-minute practice
- Change the notebook price and quantity in the first example.
- Use your own name in the greeting.
- Predict the output before running each program.
- Explain what happens after the practice button is clicked.
Further reading
- MDN: What is JavaScript? ↗
- MDN: JavaScript introduction ↗
- Node.js: Introduction to Node.js ↗
- Ecma International: ECMAScript specification ↗
Give your first idea a try.
Explore the JavaScript course outline, or sign in to practise with your active course enrollment.

