JavaScript Program To Print Hello World: In 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!”.
- Using document.write() function
- Using alert() function
- 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!