JavaScript is the language that brings web pages to life. It runs in every browser and, with Node.js, it also works on servers, scripts and command line tools.
How it works
When you open a site, the browser downloads the HTML, CSS and JavaScript. HTML defines the structure, CSS the look, and JavaScript the behavior: what happens when you click, submit a form or load new data.
The code runs in an engine inside the browser. On the server, Node.js plays the same role outside the browser.
The language is dynamically typed and handles long running tasks, such as network calls, using promises and async/await. This avoids freezing the page while waiting for a response.
Many people use TypeScript, a version that adds types to JavaScript, to catch errors before runtime.
Practical example
You have a pizzeria site and want to show the order total without reloading the page. With JavaScript, you listen for the click on the add button and update the value on screen.
const preco = 45;
let quantidade = 0;
document.querySelector('#mais').addEventListener('click', () => {
quantidade += 1;
document.querySelector('#total').textContent = `R$ ${preco * quantidade}`;
});The same knowledge lets you call an AI API and show an assistant's response inside the site.
What it's used for
JavaScript is used for interactive sites, web apps, servers, automations, browser extensions and mobile apps with frameworks like React Native.
In the AI world, it is widely used to build chat interfaces, integrate models via API and build agents. Coding assistants tend to generate JavaScript easily because there is a lot of public code in the language.
Difference between JavaScript and Node.js
JavaScript is the language. Node.js is a runtime that lets you run it outside the browser. In other words, you write JavaScript and choose where it runs: in the browser, in Node.js or in other compatible environments.