First Hello World Program in JavaScript
First Hello World Program in JavaScript
1. Text Editor : I will be using Visual Studio Code Text Editor which is highly recommended by many
specially for Javascript, however you can use any other text editor like Notepad++ or Sublime text etc.
2. Browser : Of course a browser is needed to load the HTML document and run the JavaScript so I will be
using Google Chrome broswer. You can use any browser of your choice as most modern browsers have JavaScript
enabled by default.
There are 2 ways to include JavaScript in your HTML Document –
default.html file –
1 <html>
2 <head>
3 <title>My title</title>
4 <script type="text/javascript">
5 document.write("<h1>JS Embedded</h1>");
6 </script>
7 </head>
8 <body>
9 </body>
10</html>
Output –
default.html file –
1<html>
2<head>
3<title>My title</title>
4<script src="demo.js" type="text/javascript"></script>
5
6</head>
7<body>
8</body>
9</html>
demo.js file –
1document.write("<h1>External file</h1>");
Output –
So thats it for this basic hello world starter program where we simple printed text on the HTML document(not exactly hello
world but you get the point right