Hello World Program | First Program in JavaScript

Characteristics | Advantages | Limitations of JavaScript

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

A “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()

Using console.log()

console.log() is used to print any kind of message on debug console. This function is very useful in daily life development in JavaScript. As javascript or frontend developer, we are using this function very frequently to debug something, to view any kind of variable value or explore the response from APIs.

// the hello world program
console.log('Hello World');
a = 10;
console.log('Value of a is: ', a);

Output

Hello, World!
Value of a is: 10

Here, the first line is a comment.

// the hello world program

Using alert()

The alert() method displays an alert box over the current window with the specified message. This method could be use to show some message to user, to as some input from user.

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

Using document.write()

document.write() is used when you want to print the content to the HTML tags. Such as input box, text area, div or table etc.

// the hello world program 
document.write('Hello, World!');
Hello World Program | First Program in JavaScript
Show Buttons
Hide Buttons