What is JavaScript

Open a web page and click a button that opens a menu, type into a search box that suggests results as you go, or watch a feed load more posts as you scroll. None of that is HTML, and none of it is CSS. It is JavaScript: the language that runs inside the browser and makes a page respond to what you do. This chapter is about what that language is, where it runs, and how it fits with the HTML and CSS you already know.
A language for making pages do things
JavaScript is a programming language: a way of writing instructions that a computer carries out step by step. Where HTML describes what is on a page and CSS describes how it looks, JavaScript describes what happens. It is the part that reacts.
Think of a web page as a house. HTML is the structure, the walls and rooms. CSS is the paint and furniture. JavaScript is the electricity and plumbing: the wiring that makes a switch turn on a light, or a tap produce water. It is what makes the page do something when a person interacts with it.
// HTML gives you a button. JavaScript makes it do something.
const button = document.querySelector(".menu-toggle");
button.addEventListener("click", openMenu);You will meet every piece of that in later chapters. For now, notice the shape: JavaScript reaches into the page (document.querySelector), and it responds to something the user does (addEventListener). Reaching in and responding are most of what browser JavaScript does.
Where JavaScript runs
JavaScript runs inside the browser. Every browser, Chrome, Safari, Firefox, has a built-in engine that reads your JavaScript and runs it. That means there is nothing to install to get started: if you can open a web page, you can run JavaScript.
You add JavaScript to a page with a <script> tag, usually right before the closing </body> tag, To keep your code in its own file, point the tag at it with a src attribute that names the file, the same way an image tag points at an image.
The quickest place to try a line of code is the browser console, a panel in the developer tools where you can type JavaScript and see the result straight away.
<script> tag, and the fastest place to try a line is the console in the browser's developer tools. Open it and type something, you cannot break anything. Your first look at JavaScript
Here is a tiny program. You do not need to understand every part yet, the next chapters cover each one, but you can already read the shape of it:
let name = "Sam";
console.log("Hi " + name); // Hi SamThe first line stores the text "Sam" under the name name. The second line prints a message to the console, joining "Hi " and the stored name together. console.log is how you ask JavaScript to show you a value while you are learning, and you will use it constantly.
console.log prints a value so you can see it, and it is your best friend while learning. Do not worry about the details yet, you will meet each part properly in the next chapters. What "modern JavaScript" means
You will hear people talk about modern JavaScript. JavaScript has been around since 1995 and it gets new features every year, but old code keeps working, so the language has picked up a few different ways to do the same thing over the years.
The good news: you do not need the history. This handbook teaches the current, recommended way to write each thing. If you see older tutorials using var to make variables, that is the old style; you will learn let and const instead, which are what developers use today.
var, that is the old style, and you will learn let and const instead. Where JavaScript goes from here
JavaScript is a large language, but it starts small: values, names for them, and ways to combine and act on them. Once those click, the rest of this handbook builds outward: making decisions and repeating work, organising code into functions, holding collections in arrays and objects, and then reaching into the page itself with the DOM to build things people can actually use.
The next chapter, variables, is where the real work begins: how to store a value, the difference between let and const, and the small set of rules that the whole rest of the language is built on.

