What is JavaScript ?

JavaScript is:

  • JavaScript is a lightweight, interpreted programming language
    • Designed for creating network-centric applications
    • Complementary to and integrated with Java
    • Complementary to and integrated with HTML
    • Open and cross-platform

JavaScript Syntax:

  1. A JavaScript consists of JavaScript statements that are placed within the <script>… </script> HTML tags in a web page.
  2. You can place the <script> tag containing your JavaScript anywhere within you web page but it is preferred way to keep it within the <head> tags.
  3. The <script> tag alert the browser program to begin interpreting all the text between these tags as a script. So simple syntax of your JavaScript will be as follows
<script ...>
  JavaScript code

The script tag takes two important attributes:

  • language: This attribute specifies what scripting language you are using. Typically, its value will be javascript. Although recent versions of HTML (and XHTML, its successor) have phased out the use of this attribute.
  • type: This attribute is what is now recommended to indicate the scripting language in use and its value should be set to “text/javascript”.

So your JavaScript segment will look like:

<script language="javascript" type="text/javascript">
  JavaScript code

Your First JavaScript Script:

Let us write our class example to print out “Hello World”.

<script language="javascript" type="text/javascript">
   document.write("Hello World!")

Hello World!