Introduction
Every web developer in the tech world knows about Javascript. And why would they not? It is a famous language to create the front-end portion of any dynamic webpage. Its users love it for its lightweight nature and huge demand resulting in high pay in the job market. This blog will instruct you on how to write a hello world program in JavaScript. A JavaScript hello world program is the most commonly used method to introduce a language to a newbie.
JavaScript Hello World Program
We will soon head to print a JavaScript program to print Hello World on the output screen. But before that, let's get a bit into the theory of what we are about to implement.
Any text editor can embed your JavaScript hello world code into an HTML page. The JavaScript code is embedded into an HTML page through a <script> tag. We place the <script> tag either in the head tag or body tag.
JavaScript is a client-side scripting language. So, it provides the user with three ways to print the sentences (output).
- document.write()
- console.log()
-
alert()
Each of these methods prints the JavaScript hello world output in different ways. The ‘document.write()’ is used to print the strings on the webpage. ‘console.log()’ is mainly used while debugging, and the ‘alert()’ is used when we want the output in a dialog box popping up on the screen. So, you can actually print your JavaScript hello world code in three ways. Interesting right?