What is JavaScript?
JavaScript is a programming language that is used to make the web interactive. When you click a button in a website and something happens, or when a form warns you before you submit it, or when a page updates without refreshing—that is JavaScript working in the background enabling the web to give feedback to actions taken by the user.
This JavaScript capability of making the web interactive works with two other technologies that form the basic tools used for web development:
- HTML provides the content and structure of the webpage.
- CSS styles the content.
- JavaScript controls the behavior of the webpage.
A way to sum up JavaScript's importance in this relationship is that without it, websites would be unresponsive and boring.
While JavaScript was primarily built for the browser, the technology has evolved to become more powerful. Today, JavaScript is used to create websites, run servers (Node.js), power mobile apps, desktop applications, and even control hardware.
JavaScript is sometimes compared unfavourably to lower-level languages like C and C++, but this framing misses the point. C and C++ give developers fine-grained control over memory and hardware at the cost of complexity and development speed. JavaScript intentionally abstracts those concerns away. Every language has trade-offs, and JavaScript's trade-offs are optimised for the web — which is why it is used by big companies like Google, Netflix, and Meta.
Where JavaScript Runs (Browser vs Server)
JavaScript can run in two main places: the browser and the server. Same language but doing different jobs.
JavaScript in the Browser
The browser is where JavaScript started from and what it was built for. JavaScript's job in the browser is to enable the webpage to interact with the user. This means when a button is clicked or any other kind of action is taken on the webpage, the page reacts to the user's actions.
Some of its functions in the browser are:
- To respond to clicks, typing, and scrolling.
- Manipulate the DOM (change text, images, layouts).
- Validate forms before submission.
- Fetch data from servers without reloading the page.
JavaScript on the Server
To be able to execute JavaScript code outside the browser, Node.js is used. Node.js is a cross-platform JavaScript runtime environment that allows JavaScript code to work outside the browser where it was originally intended to be used.
"Cross-platform JavaScript runtime environment" means Node.js acts as a universal translator that enables JavaScript to run on different operating systems (OS), while also taking JavaScript out of its normal environment (the browser) and putting it in another environment so it can perform other functions like being a web server.
Some of the things server-side JavaScript can do are:
- Handle HTTP requests and responses.
- Connect to databases.
- Authenticate users.
- Process payments.
- Run background jobs and scheduled tasks.
- Power APIs used by mobile apps and websites.
The JavaScript code used in the browser and server follow the same syntax. What is different is the environment they operate in; one in the browser and the other in the server. This different environment gives them different capabilities and functions. The browser enables interactive web design, and the server enables logic.
The different environments JavaScript is able to operate in is what makes it powerful and popular. This means a single developer can build both the frontend of a project and also its backend, and share logic across both.
What can be Built with JavaScript
JavaScript is no longer a language constrained to the web. It is now a general-purpose language that can be used to build different things. Examples are:
- Interactive Websites & Web Apps
- Backend Servers & APIs
- Mobile Applications
- Desktop Applications
- Games
- Automation & Scripting (e.g., Task scheduling)
Few languages stretch this wide.
Features of JavaScript as a Programming Language
Understanding JavaScript's core characteristics is important.
High-Level Language
JavaScript is a high-level programming language. This means it handles many low-level details for the developer, such as memory management, hardware interaction, and system complexity.
Dynamically Typed
In JavaScript, variables don't have fixed types. This means a variable can hold a number now and a string later. Dynamic typing makes JavaScript easy to start with but also makes it loose and susceptible to bugs. This is why tools like TypeScript exist—to add structure and discipline where JavaScript stays loose.
Single-Threaded
JavaScript is a single-threaded language. This means JavaScript can do only one thing at a time; if a piece of code is running, everything else waits for it to finish. It doesn't multitask. This is called synchronous code.
Despite being single-threaded, JavaScript can still handle tasks asynchronously — meaning it can defer certain operations (like waiting for a network response) and move on to other code in the meantime, then come back to handle the result when it's ready. This is not true parallelism; JavaScript is still only doing one thing at a time. What makes this possible is the event loop — a mechanism in the browser and Node.js runtime that continuously checks whether deferred tasks are ready to be executed and processes them when they are.
The features that enable asynchronous behaviour in JavaScript evolved over time. Callback functions came first — functions passed as arguments to be called once a task completes. Promises improved on callbacks by providing a cleaner way to handle success and failure. Async/await is the modern syntax built on top of promises, making asynchronous code read more like synchronous code. All three exist in the language today, which is why you will encounter all of them in the wild.
Interpreted (and Just-In-Time Compiled)
JavaScript code isn't compiled ahead of time like C or Java. Instead, it's executed by an engine that reads the code and runs it—often using Just-In-Time (JIT) compilation to optimize performance while the program is running.