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:



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


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

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


Don't Miss

  • Unity
    'Assassin's Creed Unity' preview: Ubisoft comes home to its urban origins
    Games Preview
  • Smart vending machine
    This smart vending machine will recommend drinks for you based on your gender and age
    Tech Buzz
  • Destiny
    The 'Destiny' beta: 7 things we absolutely love about Bungie's new franchise
    Games Feature
  • Wi-Fi
    Find out how to stretch your Wi-Fi signal where it has never gone before
    Tech Tips
  • Unity Exclusive
    'Assassin's Creed Unity' exclusive: Tell the world, 'I'm coming home'
    Games Interview
  • Gamer ghost
    Gamer finds and plays with ghost of deceased father on a classic game