In Seven Ways, Print Hello Coders in JavaScript

Now I shall write a very basic and starting example of JavaScript. We shall print “Hello Coders” into seven ways.

Way-1:

document.writeln("Hello Coders");

Way-2:

var helloCoder="Hello Coders!";
document.writeln("Output-2: "+helloCoder+"<br/>");

Way-3:

<p id="display3"></p>
document.getElementById('display3').innerHTML=
"Hello Coders!";

Way-4:

<p id="display4"></p>
var hc="Hello Coders!";
document.getElementById('display4').innerHTML=hc;

Way-5:

function displayHelloCoder(){
var hc="Hello Coders!";
document.getElementById('display5').innerHTML=hc;
}
<p id="display5"></p>
<button type="button" onClick="displayHelloCoder()">
Display Hello Coders</button>

Way-6:

console.log("Hello Coders!");

Way-7:

alert("Hello Coders!");

Complete Source Code

Happy Coding!

Leave a Reply