CPCODELAB
JavaScript

What Is JavaScript and How It Runs

8 min read

What Is JavaScript?

JavaScript is a high-level, interpreted programming language that was originally created to add interactivity to web pages. Today it runs everywhere: in browsers, on servers via Node.js, in mobile apps, desktop apps, and even embedded devices.

Unlike HTML (structure) and CSS (presentation), JavaScript is responsible for behaviour. It can respond to clicks, fetch data from servers, animate elements, validate forms, and much more — all without reloading the page.

How the Browser Runs JavaScript

Every modern browser ships with a JavaScript engine — Chrome uses V8, Firefox uses SpiderMonkey, Safari uses JavaScriptCore. When a browser loads a page, the engine parses your .js files, compiles them Just-In-Time (JIT), and executes them. The engine also exposes Web APIs (DOM, fetch, timers) that your code can call.

JavaScript is single-threaded: it runs one piece of code at a time on the main thread. Long-running tasks would freeze the page, so asynchronous patterns (callbacks, Promises, async/await) let you schedule work without blocking. You will explore this in depth in the Event Loop lesson.

Adding JavaScript to a Page

html
<!-- Inline script -->
<script>
  console.log("Hello, world!");
</script>

<!-- External file (preferred) -->
<script src="main.js" defer></script>

Always use the defer attribute on external scripts. It tells the browser to download the file in parallel but execute it only after HTML parsing is complete, so your script can safely access the DOM.

Ready to test yourself?
Practice JavaScript— quiz & coding exercises