Posted by H-AZAD
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');
Output
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!');