How JavaScript runs in the browser and Node.js
JavaScript engine, V8, call stack, runtime environment, browser vs Node.js, script execution, console
How JavaScript Executes
JavaScript is a single-threaded, interpreted language. When your script runs, the engine parses it, compiles it just-in-time, and executes it line by line on a single call stack.
In the browser, the engine is built into Chrome (V8), Firefox (SpiderMonkey), or Safari (JavaScriptCore). It has access to browser APIs: document, window, fetch. In Node.js, the same V8 engine runs on your machine — no browser required — and gains access to file system, network, and OS APIs instead.
Your First Script
Every JavaScript program starts executing from the top of the file. The console.log() function writes output to the browser DevTools console or terminal.
// browser: open DevTools → Console tab
console.log("Hello, JavaScript");
// Node.js: run with node hello.js
const name = "Script Valley";
console.log("Welcome to", name);
The call stack tracks which function is currently running. When console.log is called, it is pushed onto the stack; once it returns, it is popped off. Understanding the stack is the foundation for debugging every error you will ever see.
Key Takeaway
JavaScript runs in an engine, not directly on hardware. The environment (browser or Node.js) determines which APIs are available beyond the core language.
