JavaScript Program To Print Hello World

JavaScript Program To Print Hello WorldIn this tutorial we will follow the ritual of every programming learning practice, it is to print “Hello World“. We will learn what are the ways to print something e.g “Hello world” in JavaScript. Since this is a very simple program to print “Hello world”, it is often use to introduce new programming language to any beginner.

In this tutorial we will use 3 methods to print “Hello world!”.

  1. Using document.write() function
  2. Using alert() function
  3. Using console.log() function

Using document.write() function

The function document.write() is used to print the content in the HTML page.

Source code

[javascript]document.write(‘Hello, World!’);[/javascript]

Output

Hello, World!

Using alert() function

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

Source code

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

Output

Hello, World!

Using console.log() function

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

Source code

[javascript]// the hello world program
consolee.log("Hello, World!);[/javascript]

Output

Hello, World!

Write for us
GeekyBeginners articles are written by software geeks like you. If you also would like to contribute to GeekyBeginners by writing paid articles, you can check the write for us page.

Leave a Comment