Skip to main content
  1. Tech
  2. Gadgets & Tech
  3. Internet

How to write a simple JavaScript program

See also

JavaScript is the most popular programming language in the world. It is also easy to learn. All web browsers can run JavaScript code. The JavaScript code below displays the words Hello World! in a web browser. Create a text file called HelloWorld.html and enter these lines:

<!DOCTYPE HTML>

<html>
<body>

<script type="text/javascript">
document.writeln("<h1>Hello World!</h1>");
</script>

</body>
</html>

Save this text file and double-click it to display the web page. You will see the words Hello World! in the web browser. This code is a typical HTML page. It includes the standard <html> and <body> tags.

The JavaScript code is included in the <script> tag. The document.writeln() method writes text to the document output. In this case, it writes a <h1> tag with the words Hello World! So you can use JavaScript to write HTML elements.

This is just a simple JavaScript example. For more information on JavaScript programming, visit the online tutorials at w3schools.com.

For more articles, please subscribe, add or follow me here.

Advertisement