Lesson 1 of 18 · 0 of 1 exercises solved

Hello, World!

You will print your first message and see the two places JavaScript runs: the browser console and Node.js. You can try it now by opening DevTools (F12) and clicking Console.

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

// 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}!`);
JavaScript sandboxCtrl+Enter runs

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

// 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>
JavaScript sandboxCtrl+Enter runs

Practice

Log Hello, ScholastiCoder! on the first line, then log the result of 6 * 7 on the second. console.log accepts any value, not only .

Exercise

Two logs

2 checks
console.log("Hello, World!")
 
JavaScript sandboxCtrl+Enter runs
Output
Press Run to try your code, then Check answer to grade it.

Check yourself

Quick check

Where does console.log("hi") show its output when run in a browser?

Finished reading?1 exercise still open. You can come back to it later.

Tip: use the ← and → keys to move between lessons.