---
title: "JavaScript"  
description: "JavaScript is basically used for validating web pages at the client end. Its task is to validate the user input on the web pages, thus saving the serv"  
author: "Danish Khan"  
published: 2012-10-06  
updated: 2017-11-29  
canonical: https://www.mindstick.com/articles/1036/javascript  
category: "javascript"  
tags: ["javascript"]  
reading_time: 4 minutes  

---

# JavaScript

[Introduction](https://yourviews.mindstick.com/view/85450/mesopotamia-introduction-to-an-ancient-civilization):\

JavaScript is basically used for validating [web pages](https://answers.mindstick.com/qa/95530/how-do-i-fix-safari-not-loading-web-pages) at the client end. Its task is to validate the [user input](https://www.mindstick.com/forum/159624/setting-an-enum-from-user-input) on the web pages, thus saving the server resources.

The statements are placed within the <script> </script> HTML tags. The <script> </script> tags alert the browser to interpret all the statement written between the script tags as a script. Script is a [client side](https://www.mindstick.com/forum/160418/what-are-the-best-practices-for-securely-storing-bearer-tokens-on-the-client-side) program; it is used to extend the [functionality](https://www.mindstick.com/blog/136/using-watermark-functionality-in-textbox-by-jquery) of html documents and to handle it in the most [interactive](https://answers.mindstick.com/qa/38931/who-has-won-the-2016-fifa-interactive-world-cup-fiwc) way. The correct place to keep these script tags is in the <head> </head> section but we can place it anywhere on the [web page](https://answers.mindstick.com/qa/92898/how-to-create-a-web-page-using-bootstrap-4).

##### There are two important attribute of a script tag:

1. **Language:** It specifies which language version we are using, basically the language is Java Script.

2. **Type:** This attribute is used to indicate the [scripting language](https://www.mindstick.com/blog/486/scripting-language) to use; its value will be text/javascript.

This is first part of the Java Script code:

```
<script type="text/javascript">
    //Java Script Code to be written here     
</script> 
```

The above program would not print anything on the browser.

\

There is a function of a JavaScript [known as](https://answers.mindstick.com/qa/38482/name-the-world-s-lightest-material-which-was-manufactured-by-isro-scientists-at-the-vikram-sarabhai-space-centre-thiruvananthapuram-and-is-also-known-as-blue-air) document.write (), this function is used

\

to print the string on the browsers screen.

```
<html xmlns="http://www.w3.org/1999/xhtml">  <head runat="server">  <title></title>
  <script type="text/javascript">     <!--      function displayMsg()      {        document.write("Hello! Welcome to the world of JavaScript")      }      -->  </head>
     <body>  <input id="btnSubmit" type="button" value="Display Message" onclick="displayMsg()"/>     
  </body>  </html>
```

##### Output of the above code:

Hello! Welcome to the world of JavaScript

The above lines will be printed on the browsers screen.

\

There are places when some browsers do not support Java script code, there are

\

[compatibility](https://www.mindstick.com/blog/303291/best-practices-for-working-with-host-apis-security-compatibility-and-performance-considerations) issue so there we use comment <! — Comment /-->. This will prevent

\

the browser in executing the lines of code that are placed in the comment

\

section when there are compatibility issues as shown in the example.

```
<script type="text/javascript"><!--    function UsingComment() {
        alert("Showing the use of Comment")
    }--> </script> 
```

Few Points to remember Java Script:

1. JavaScript is a case-sensitive language. For eg. Document.write() function is

\

different from the document.write() function, the first one will not print any output

\

on the screen. So care must be taken in typing the variables, function names and

\

any other identifiers otherwise program will not give the correct output.

2. JavaScript ignores white spaces, tabs and new lines. We can use as much

\

spaces we want to give a beautiful look to our program.

3. Simple statements are usually followed by semicolons but it is not

\

compulsory if to place semicolons if both the statements are on different lines.

##### For example:

var a = 40

var b = 25

The above code are allowed in JavaScript if they both are written on different lines.

But we have to give semicolons between them if we have both the statements on

\

the same line as follows var a= 40; var b=25;

4. As every language has comments same with the JavaScript, JavaScript supports

\

both C / C++ styles of code.

##### Single Line Comment:

#####

// This is a single Line comment.

##### Multiple Lines Comment :

```
    /*
    This is a multiline
    comment in
    JavaScript
    */
```

Conclusion:

This article gives you knowledge about Java Script and how to declare

\

sections of Java Script in our html page. Which syntax to use while declaring Java

\

Script sections of code in our html page. How to use comments in our Java Script

\

programs and so on.

---

Original Source: https://www.mindstick.com/articles/1036/javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
