Module 1: Getting Started with JavaScript
JavaScript Runtimes and Setup
Choose a browser or Node.js environment and understand the role of the JavaScript engine.
JavaScript source code is executed by a runtime. The runtime includes a JavaScript engine and the surrounding APIs available to a program. Browsers typically provide the DOM, timers, fetch, and web storage. Node.js provides APIs for files, processes, networking, and packages.
The language is standardized by ECMAScript, while many APIs depend on the host environment. For example, document.querySelector belongs to the browser DOM; it is not part of the core JavaScript language and is not normally available in Node.js.
Start in the browser#
Open your browser's developer tools and select the Console panel. Try:
const language = "JavaScript";
console.log(`${language} is running`);
The console is useful for quick experiments, but save meaningful programs in files so they can be version-controlled and tested.
Start with Node.js#
Install a supported Node.js release from the official Node.js website if you want to run local JavaScript files. Create hello.js:
console.log("Hello from Node.js");
Run it in a terminal with node hello.js. Browser and Node.js versions may expose different APIs, so check where a feature is supported before using it.
Editor and project habits#
Use an editor with syntax highlighting, keep files in a project folder, and use clear filenames. Do not paste unknown code into a console or terminal. For larger projects, package managers and automated tests become important; they are covered later.
Practice#
Run one statement in the browser console and one in a Node.js file. Note which environment-specific APIs are available in each.