How to print Hello World

Print to the console

console.log() writes values to developer tools in a browser or to the terminal in Node.js.

console.log("Hello, World!");

Print more than one value

Separate arguments with commas. This avoids manual conversion and lets consoles inspect objects clearly.

const language = "JavaScript";
const year = 1995;
console.log("Learning", language, "created in", year);

Display text on a web page

In a browser, select an element and update its text. textContent treats the value as text rather than HTML.

<h1 id="greeting"></h1>
<script>
  const heading = document.querySelector("#greeting");
  heading.textContent = "Hello, World!";
</script>

Use output intentionally

  • Use console.log while learning and debugging
  • Use console.error for failures and console.warn for warnings
  • Do not rely on console output as the user interface of a web page
  • Prefer semicolons consistently, even though JavaScript can insert many automatically