"Hello, World!" is traditionally the first program anyone writes in a new language, and JavaScript is no exception. It is a tiny program, but it confirms that your environment — a browser console, Node.js, or an online editor — is set up correctly and that you understand the basic syntax for printing output.
In JavaScript, the most common way to print text is the console.log() function, which writes a message to the console (the browser's DevTools console, or the terminal if you are running the file with Node.js).
Program to Print "Hello, World!" in JavaScript
// This program prints Hello, World! to the console
console.log("Hello, World!");
Output:
Hello, World!
That's it — one line is enough. console.log() can print strings, numbers, objects, and arrays, and it accepts multiple comma-separated values which it prints space-separated on the same line. If you save this code in a file named hello.js and run node hello.js in a terminal, or paste it directly into your browser's console, you will see the same output.
Once you're comfortable with this, a natural next step is printing a sequence of values using a loop instead of a single line.
