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}!`);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>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 .
Two logs
console.log("Hello, World!")
Press Run to try your code, then Check answer to grade it.Check yourself
Where does console.log("hi") show its output when run in a browser?
Tip: use the ← and → keys to move between lessons.