JS Example for Beginners: JavaScript Program To Print Hello World

Hits: 16

(JavaScript programming Example for Beginners)

JavaScript Program To Print Hello World

In this example, you will learn to print ‘Hello World’ in JavaScript in three different ways.

“Hello, World!” is a simple program that prints Hello, World! on the screen. Since it’s a very simple program, this program is often used to introduce a new programming language to beginners.

We will use these three ways to print 'Hello, World!'.

  • console.log()
  • alert()
  • document.write()

1. Using console.log()

console.log() is used in debugging the code.

Source Code

// the hello world program
console.log('Hello World');


Hello, World!

Here, the first line is a comment.

// the hello world program

The second line

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

prints the ‘Hello, World!’ string to the console.

2. Using alert()

The alert() method displays an alert box over the current window with the specified message.

Source Code

// the hello world program
alert("Hello, World!");

3. Using document.write()

document.write() is used when you want to print the content to the HTML document.

Source Code

// the hello world program
document.write('Hello, World!');


JS Example for Beginners: JavaScript Program To Print Hello World

Sign up to get end-to-end “Learn By Coding” example.

Disclaimer: The information and code presented within this recipe/tutorial is only for educational and coaching purposes for beginners and developers. Anyone can practice and apply the recipe/tutorial presented here, but the reader is taking full responsibility for his/her actions. The author (content curator) of this recipe (code / program) has made every effort to ensure the accuracy of the information was correct at time of publication. The author (content curator) does not assume and hereby disclaims any liability to any party for any loss, damage, or disruption caused by errors or omissions, whether such errors or omissions result from accident, negligence, or any other cause. The information presented here could also be found in public knowledge domains.