JSJavaScript · Lesson 1 of 14

Hello, World!

You can run JavaScript in your browser's console right now. Open DevTools (F12), click Console, and type. You're already set up. Relax.

JavaScript has two environments: the browser and Node.js. In the browser, you'd use console.log(). In Node.js, same thing. The function is identical — the output just goes to different places.

JavaScript
// In browser console or Node.js
console.log("Hello, World!");

// console has many methods
console.log("Regular message");
console.warn("Warning message");
console.error("Error message");

// Log multiple values
console.log("Name:", "Alice", "Age:", 30);

// Template literals (backticks) for string interpolation
const name = "World";
console.log(`Hello, ${name}!`);

In a browser, you can also display output in the HTML page itself. But for learning, console.log() is almost always what you want.

JavaScript
// Save as hello.js, run with: node hello.js
console.log("Hello from Node.js!");

// Or in an HTML file:
// <script>
//   document.getElementById("output").textContent = "Hello, World!";
// </script>
◆ Note
JavaScript files run top-to-bottom. There's no main() function required — code at the top level executes immediately when the file is loaded or run.