Software & Web Engineering

What Is JavaScript? The Language That Makes Websites Respond to You

Bàn làm việc buổi tối với laptop mở trang web, tách cà phê và sổ tay dưới ánh đèn vàng ấm
In this article

    You click “Add to cart” on an online shop and wonder: what is JavaScript? The number on the cart jumps from 0 to 1 at once, without reloading the page. You type an email address missing the @ sign, and a red line appears under the field before you even press submit. A menu on your phone opens when you tap the three-line icon. All three share one thing: the page knows what you just did and answers right away. The part doing that work is JavaScript.

    Quick summary

    • JavaScript is the programming language that makes web pages respond to what you do, alongside HTML for structure and CSS for appearance.
    • The browser runs JavaScript with a built-in engine, which turns code into machine code as it runs and updates the page through the DOM.
    • The same language also runs on servers, thanks to Node.js, released in 2009.
    Evening desk with a laptop showing a website, a cup of coffee, and an open notebook under a warm lamp
    Evening desk with a laptop showing a website, a cup of coffee, and an open notebook under a warm lamp

    What is JavaScript?

    JavaScript is the programming language that makes a web page respond to what you do. According to MDN, JavaScript is the third layer of the three standard web technologies, after HTML and CSS. HTML builds the frame of the page, CSS decides how the page looks, and JavaScript decides what the page does when you touch it.

    One button shows how the three layers split the work. HTML creates the button, CSS gives it color and rounded corners, and JavaScript decides what happens when you click it. Without JavaScript, a page still shows text and images, but every button, input field, and menu sits still.

    Diagram of the three layers of a web page: HTML, CSS, and JavaScript
    Diagram of the three layers of a web page: HTML, CSS, and JavaScript

    JavaScript is a scripting language, which means code is turned into machine code as it runs, instead of being compiled first into a separate executable file. Modern JavaScript engines use just-in-time compilation to run faster than the old way of translating line by line. Every popular browser has one of these engines built in.

    JavaScript is everywhere. According to W3Techs, as of 2025, 98.9% of websites use JavaScript for client-side behavior. In the Stack Overflow Developer Survey 2025, JavaScript was the most used language, with 66% of respondents saying they had used it in the past year, holding that spot for the 13th year in a row. That number measures self-reported use, not hiring demand, but it shows that a newcomer to web development will almost certainly meet JavaScript first.

    What is JavaScript and how does it run in the browser?

    The browser does not run JavaScript code in a vague way. According to AWS, the process has five steps: the browser loads the page and builds the DOM, the JavaScript engine turns the code into machine code, an event such as a mouse click triggers the code attached to it, the engine runs that code and changes the DOM, and the browser redraws the part of the page that changed.

    The DOM, short for Document Object Model, is a tree-shaped map of the page that code can read and change. Each HTML tag becomes a node on that tree. When JavaScript changes a node, the browser redraws only that spot, and the rest of the page stays as it is. That is why the cart number goes up without reloading the page.

    Each browser has its own JavaScript engine: Chrome and Edge use V8, Safari uses JavaScriptCore, Firefox uses SpiderMonkey. The JavaScript you write runs on all three, because they all follow the same language standard. JavaScript in the browser can only touch what the browser allows, for example it cannot write straight to your hard disk unless you click download. That limit is deliberate: the code runs on the reader’s machine, so the browser has to keep it inside a safe boundary.

    Your first lines of JavaScript

    You need to install nothing to try JavaScript. Open any web page, press F12, and pick the Console tab. The blinking cursor there is where you type code and see the result at once. Type this line and press Enter:

    2 + 3

    The console returns 5. Nothing impressive yet, but you just ran real JavaScript in your own browser. Now try an example closer to real work: adding up a shopping cart. Suppose a small shop sells coffee and milk tea, and the cart holds two items. Type this code into the console:

    const cart = [
      { name: "Arabica coffee", price: 45000, quantity: 2 },
      { name: "Milk tea", price: 35000, quantity: 1 },
    ];
    let total = 0;
    for (const item of cart) {
      total += item.price * item.quantity;
    }
    console.log(total);

    The console prints 125000. Each line does one small job: const cart holds the list of items, each with a name, a price, and a quantity; let total = 0 sets the starting total to zero; the for loop walks through each item and adds price times quantity to the total; console.log(total) prints the total on screen. Check it by hand: 45,000 times 2 is 90,000, plus 35,000 is 125,000, which matches what the code printed. Prices are in Vietnamese dong. This code was actually run with Node.js version 24.22.1 on 3 December 2026, and the result was exactly 125000.

    JavaScript in the browser can also read the page you are looking at. Type this line into the console of any page:

    document.querySelectorAll("a").length

    The console returns the number of links on that page. document is the doorway into the DOM, querySelectorAll("a") picks every link tag, and .length counts them. In the same style, you can pick a button and attach a response to it:

    const button = document.querySelector("button");
    button.addEventListener("click", () => {
      console.log("You just clicked the button");
    });

    This code tells the browser: when someone clicks the first button on the page, print that line to the console. addEventListener is how JavaScript listens for events, and “event” is the central idea of the language: the code sits and waits for the user to do something, then responds.

    What is JavaScript and how is it different from Java?

    The similar names lead many newcomers to think JavaScript is a cut-down version of Java. The two languages differ in design, according to both Wikipedia and MDN. The name JavaScript was partly a marketing decision by Netscape, because Java was rising fast at the time.

    JavaScriptJava
    TypingDynamic typing, variables need no type declared in advanceStatic typing, variables must declare their type
    How it runsTurned into machine code as it runs, in the browser or on a server through Node.jsCompiled first into bytecode, run on the Java Virtual Machine
    Where it is usedMainly interactive web pages, then extended to servers and mobile appsLarge enterprise applications, Android apps, server-side systems

    The one real thing they share is borrowed syntax: both use curly braces, semicolons, and many keywords that look alike. Learning Java does not teach you JavaScript, and the other way around.

    JavaScript does not only run in the browser

    In 2009, Ryan Dahl created Node.js, a runtime for running JavaScript on a server, built on the V8 engine. Since then, one language can write both sides of a website: code in the browser handles the mouse click, code on the server takes the data sent up, asks the database, and sends the result back.

    Node.js calls itself a runtime, not a framework. It runs in an event-driven way: instead of waiting for each task to finish before starting the next, it takes a request, registers what to do when the result arrives, and moves on to the next request. That fits the work of a web server, where most of the time goes to waiting for a database or a network. According to Node.js, HTTP is treated as a first-class citizen in this environment, because it was built to make network applications.

    Thanks to Node.js, learning JavaScript does not stop at static pages. A signup form in the browser sends data with JavaScript, a Node.js server receives it and stores it in a database with what SQL is, then sends the result back for the browser to show. To see how the browser and the server talk to each other, read what an API is and how it works.

    How did JavaScript come about?

    JavaScript was created in 1995 at Netscape, by Brendan Eich. Netscape needed a language that people who were not professional programmers could still use to add interaction to a web page. The first prototype, codenamed Mocha, was written by Eich in about ten days in May 1995, then refined for months before release. The language first appeared as LiveScript in a beta of the Navigator browser in September 1995, then took the name JavaScript for the official release in December 1995.

    In November 1996, Netscape submitted JavaScript to Ecma International for standardization. The first standard, named ECMAScript, came out in June 1997. The name ECMAScript was a compromise between Netscape and Microsoft, which had built a similar version called JScript.

    The ECMAScript standard still gets a new edition every year. A notable update was ES6, released in 2015, which added much of the syntax modern JavaScript code still uses. The 16th edition, ES2025, came out in June 2025. Newcomers do not need to remember all of this history, only that code written to the new standard still runs on older browsers through conversion tools, so it is safe to learn from the newest documentation.

    Three common misunderstandings

    WrongRight
    JavaScript is only for pretty effects on a web pageEffects are only one part. JavaScript checks forms before they are sent, calls APIs for fresh data, stores data in the browser, and runs on the server through Node.js
    JavaScript is a cut-down version of JavaTwo separate languages, different in design. The names are close for marketing reasons, from a time when Java was rising
    You must learn all the syntax before you can build anythingReading one short piece of code, changing one spot, and seeing the page change is already a start. Syntax is learned step by step, following the work at hand

    The third misunderstanding is worth one more line, because it holds many people back. JavaScript has a large amount of syntax, but the part you use every day is small: variables, functions, conditions, loops, and listening for events. Those five are enough to add interaction to a web page.

    Where to start learning JavaScript

    1. Try it in the console. Open the console on any page, type a few sums, then run the cart example above with different items and prices. Change a quantity and watch the total follow. You just edited real code and saw a real result.
    2. Build one small page of your own. Make an HTML file with a button and a line of text. Write a few lines of JavaScript so the text changes when you click the button. The page needs no server; open the file straight in the browser and it runs.
    3. When you want to save data for real, learn the server side. Data in the browser is gone when you close the page. To keep a cart after the customer leaves, you need a server and a database. Read what SQL is to see how a server asks for data, then learn Node.js to write a server in the JavaScript you already know.

    Frequently asked questions

    Is JavaScript free?

    Yes. JavaScript is an open language, the ECMAScript standard is public, and every browser runs it without charging a fee. You need no license and no paid tool to start.

    How long does it take to learn JavaScript well enough to build a website?

    A few weeks with the syntax is enough to add interaction to a static page: a menu that opens, a form that reports errors, a button that changes content. Building a full application, with login and saved data, takes months more, plus learning servers and databases.

    What happens to a website when JavaScript is turned off?

    The content and appearance, handled by HTML and CSS, still show up, but the interactive parts stop: buttons do not respond, forms are not checked at once, and content that loads later never appears. Many pages show a warning when they detect JavaScript is off.

    Can JavaScript be used to make games?

    Yes. Many simple games run straight in the browser in JavaScript, drawn with canvas or WebGL. Large, graphics-heavy games still use dedicated engines.


    JavaScript is the language that makes a web page respond to you, and the fastest way to understand it is to run it. Open the console, type the cart example, change one number, and watch the total follow.

    Sources

    1. MDN, “What is JavaScript?”, https://developer.mozilla.org/en-US/docs/Learn_web_development/Core/Scripting/What_is_JavaScript, accessed 3 December 2026
    2. MDN, “Introduction”, JavaScript Guide, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Introduction, accessed 3 December 2026
    3. Amazon Web Services, “What is JavaScript? – JavaScript (JS) Explained”, https://aws.amazon.com/what-is/javascript/, accessed 3 December 2026
    4. Wikipedia, “JavaScript”, https://en.wikipedia.org/wiki/JavaScript, accessed 3 December 2026
    5. Node.js, “About Node.js”, https://nodejs.org/en/about, accessed 3 December 2026
    6. TC39, “ECMAScript 2025 Language Specification”, https://tc39.es/ecma262/, accessed 3 December 2026
    7. Stack Overflow, “Developer Survey 2025”, https://survey.stackoverflow.co/2025/technology, accessed 3 December 2026. The ranking table did not render as text when opened; the 66% figure and the 13-year run follow secondary reporting of the survey: ChartKite, https://www.chartkite.com/stackoverflow-survey; dev.to, https://dev.to/adilsoukaini/stack-overflow-developer-survey-2025-takeaways-for-founders-3cio
    8. Swarchitect, “History of JavaScript: 10 days”, https://www.swarchitect.net/en/history-javascript-10-days/, accessed 3 December 2026. Source for the detail that the Mocha prototype was written in about ten days; the other history facts follow Wikipedia (source 4)
    Assistant Gnurt

    Full-stack developer

    Discuss your project

    Comments

    No comments yet. Be the first!