JavaScript/First Program

From Wikibooks, the open-content textbooks collection

< JavaScript(Redirected from JavaScript/First Program (Hello World!))
Jump to: navigation, search
Previous: JavaScript Tutorial Index Next: Operators and Expressions

Here you have a single JavaScript statement:

  alert("Hello World!");

This statement will pop-up a dialog box saying 'Hello World'. The statement must be placed inside a script element.

   <script type="text/javascript">
     alert("Hello World!");
   </script>

The script element should then be nested inside the head element of a HTML document. Assuming the page is viewed in a browser that has JavaScript enabled the browser will execute (carry out) the statement as the page is loading.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
  <head>
    <title>Some Page</title>
    <script type="text/javascript">
      alert("Hello World!");
    </script>
  </head>
  <body>
    <p>The content of the web page.</p>
  </body>
</html>

This is only the beginning...

Previous: JavaScript Tutorial Index Next: Operators and Expressions
Personal tools
Create a book
  • Add wiki page
  • Collections help
In other languages