Bright Java Tutorial

is brought to you by DoITBright LLC

Javascript

Writing Your First Javascript

Most often, when people speak about Javascript, they are referring to a client side program that goes together with an HTML document. Having said this, it is assumed that you have previous knowledge about HTML. If not, I highly advise you to go over my HTML tutorial before proceeding in learning Javascript. I have mentioned that Javascript is a client side program. Client side programs are those that run on our local machine. That's right! Javascripts and HTML are loaded on our computers and run on our computers. Let us now write our first Javascript program.

  <html>
    <head>
      <title>This is my page title.</title>
    </head>
    <body>
       Hello world of HTML!<br/>
       <script type="text/javascript">
         document.write("Hello world of Javascript!");
       </script>
    </body>
  </html>
                           
You may copy and paste the above code into your favorite text editor. Then make sure to save it as an HTML document. Here is how the page will look like when you open it on your favorite browser.

First Javascript Program

Javascripts are placed between the <script> and </script> tags. We can either place our script tags between the <head> and </head> tags, or between the <body> and </body> tags. You must have noticed that the 'document.write' is a command to write something on your HTML page. At the end of the command, you must have noticed that it ended with a semicolon. As we write more Javascript programs, pay close attention to the semicolons.


Next