How To Write a Hello World Program in JavaScript

In this post, I will show you how to write a hello world program in JavaScript. It is very simple to write hello world program in JavaScript with few lines.

Let’s see

HTML

<div id="mydiv2"></div>

JAVASCRIPT

<script type="text/javascript">
document.getElementById("mydiv2").innerHTML = "Hello, world!";
</script>

Here I have used document.getElementById method to return the element with specific id. InnerHTML property is used here to set the HTML content to the selected element.

Also Read: How to Get Value of Div Content Using jQuery

Hope you have learned how to write Hello World in Javascript. If you have any query regarding this article, feel free to comment.

Leave a Comment