What is JavaScript?

Updated on     Kisan Patel

JavaScript is the scripting language supported by most of the browsers and is used to add functionality, validate forms and make the web page more interactive. JavaScript is a case sensitive language.

Each JavaScript statement should be terminated using ; (semi colon) character.

JavaScript code can also be grouped using opening braces { and closing curly braces }.

<script type="text/javascript">
....
....
....
</script>

The single line comment can start with // (double forward slashes) and multi-line comment should be wrapped inside /* (forward slash and asterisk) and */ (asterisk and forward slash) characters.

<script type="text/javascript"> 
 /* This is a comment */
</script>

The document.write Property

To print the desired message on the web browser we write the message in double quotes inside the document.write method.

document.write("Great India");

Let us write the first JavaScript by which some message will be displayed on the web page.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
      <title>My First JavaScript</title>
  </head>
  <body>
       <script type="text/javascript"> 
            /* This is the First JavaScript */
            document.write("Welcome to First Page of JavaScript");
       </script>
  </body>
</html>

Here is the output of the above code…

first-javascript

JavaScript code can be kept inside either HTML Page or in an external .js file.

If you want to write javascript code in external file then create a new .js file and write your js code in this .js file.

Note that JavaScript code is not wrapped withtag if it is written in external .js file.

Now to load external .js file in html page keep following script tag under <head></head> of the html page. Ideally the script blocks should be placed in the tag however it’s not mandatory.

<script language="javascript" type="text/javascript" src="external.js"></script>

JavaScript

Leave a Reply