JavaScript Basics

The JavaScript is an object-oriented programming language. It consists dynamic data types, operators, and methods. The JavaScript is a case-sensitive language and its syntax comes from C and Java languages. In JavaScript the semicolons are used to terminate its statements.

In HTML documents the JavaScript can be placed within the <script>...</script> tag. Generally is is recommended that the the script tag will placed within the <head> tag but it is not necessary. The example of JavaScript tag is :
<html>
<head>
  <script ...>
    JavaScript code
  </script>
</head>
<html>
<body>
  HTML Codes .........
</body>
</html>
The <script> tag alerts the browser program to start interpreting all the text between these tags as a script. The script tag will also consists two important attributes :

1. Language : The language attribute specifies what script 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.

2. Type : The type attribute indicate the scripting language in use and its value should be set to "text/JavaScript".

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

Writing The First JavaScript Code :

To write JavaScript code we do not need any special tool, instead we can do it with any simple text editor tools like notepad, notepad++ etc. For the JavaScript files the extension would be "js" or ".js".

Lets see a JavaScript example which prints "hello world" in the page.
<html>
<head>
  <title>Javascript</title>
</head>
<html>
<body>
  <script type="text/javascript">
    document.write(" Hello world !!.");
  </script>
</body>
</html>
Output :


At the above JavaScript code the document.write() function is used to print "hello world" in the page.


Next Topic :