What JavaScript Is and Where It Runs
JavaScript is a programming language. A programming language is a set of instructions a computer can follow. You write the instructions as text, and the computer runs them one by one.
JavaScript was made in 1995 so web pages could do more than just sit still. With JavaScript, a page can react: it can show a message when you click a button, check a form before you submit it, or load new data without refreshing.
JavaScript is everywhere:
- Browsers like Chrome, Firefox, and Safari run JavaScript on every web page.
- Servers (computers that send out web pages) run JavaScript too, using a tool called Node.js.
- Apps for phones and desktops can be built with it.
In this tutorial, we focus on JavaScript in the browser, because that is where most people meet it first.
How JavaScript Gets to the Page
A web page is written in HTML. HTML is a markup language: it describes the parts of a page, like headings, paragraphs, and buttons. HTML alone cannot react to the user. JavaScript adds that reaction.
You can put JavaScript in a page with a <script> tag. When the browser reads that tag, it starts running your code.
<!DOCTYPE html>
<html>
<body>
<h1>My Page</h1>
<script>
console.log('Hello from JavaScript!');
</script>
</body>
</html>console.log is a command that prints a message. You can see these messages in your browser's developer console, a panel that shows what your code prints and any errors it hits. Open it in Chrome or Firefox by pressing F12 (or right-clicking the page and choosing "Inspect").
Show diagram source
flowchart LR
A[Browser requests page] --> B[Browser reads HTML]
B --> C{script tag found}
C --> D[JavaScript code runs]
D --> E[Page can react to the user]What JavaScript Is Not
Two common confusions are worth clearing up now:
- JavaScript is not Java. They sound alike, but Java is a different language made for different jobs. The similar name was a marketing choice in the 1990s.
- JavaScript is not HTML. HTML describes what is on a page. JavaScript describes what the page does.
Why Learn It?
JavaScript is the only language every browser can run. That makes it essential for building anything interactive on the web. It is also forgiving for beginners: you can open the console and start typing right now, with no installs and no setup.
In the next chapter, you will write and run your very first JavaScript code in the browser console.
Exercise
What is the difference between HTML and JavaScript?
Show answer
HTML describes the structure and content of a page (its parts, like headings and buttons). JavaScript gives the page behavior, letting it react to clicks, input, and other events.
Exercise
Is JavaScript the same as Java?
Show answer
No. They are completely different languages. The similar names are historical, not technical.
Spotted a mistake, or code that does not work?