Friday, 14 August 2020

What is JavaScript ? and it's Syntax .

 

What is Javascript ?

Javscript is high lavel, interpreted programming language use to make  webpages  more intractive.

Javascript is scripting language that enables to create dynamic webpage and websites .It enables to controle mult-media ,animated images , etc.

It is an interpreted programming language with object oriented capabilities . 

Javascript  first known as LiveScript , but but Netscape changed its name to  JavaScript, possibly because of the excitement being generated by JAVA.

JavaScript made its first appearance in Netscape 2.0 in 1995 with the name LiveScript.

  • Javscript is lightweight programming language 
  • Javscript is have a object oriented capabilities
  • Design for creating network-centeric applications 
  • open and cross platform 

Javascript is a  client side scripting language

 

A client side scripting is common form of the language.The Script should be included refrenced by an HTML document for the code to be interpreted by Browser .

It means that a web page need note be a ststic HTML, but can included program, that interact with the user, control the browser and dynamically create HTML document .

The JavaScript client - side mechanism provides many advantages over traditional . CGI server side scripts.For example , you might use Javascript to check if the user has  entered a valid e-mail address in a form field .

The JavaScript code is executed when the user submits the form , and only if all the enteries are valid, they would be submitted to the web server.

JavaScript can be used to trap user-initiated events such as button clicks , links navigation, and other actions that the user initiates explicitly or implicity.


Advantages of JavaScript

1.Less Server interaction :- You can velidate user input before sending the page of to the server. This saves server traffic,which means less load on your server.
 

2.Immediate Feedback to visitors :- They don't have to  wait for a page reload to see they have forgot to enter something .

3.Increassed interactivity :- You can create interfaces that react when the user hovers over them with a  mouse or activates them via a keyboard.

4.Richer interfaces :- You can use JavaScript to include such items as drag-and-drop componentes or sliders to give a rich  interface to your site visitors 


Simple Syntax Of JavaScript

JavaScript can be implimented using JavaScript starments that are placed within the <script>......</script> HTML tags in a web page .

You can place the <script> tags,containing your JavaScript, anywhere within you web page, but it is normally recommnded that you  should keep it within the <head> tags.

The <script> tag allerts the browser to program to start interpreting all the text between these tags as a script. A simple syntax of your JavaScript will appeare as follows.

-----------------------------------------------------------------------------------------------------------------------------
<script....>                                                                                  
                                                                                                   
             JavaScript code 

</script>
-----------------------------------------------------------------------------------------------------------------------------

So your JavaScript syntax will look as follows.

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

So your JavaScript syntax will look as follows.
  • 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".


JavaScript are write in two ways :-
  • Internal JavaScript
  • External JavaScript

1.Internal JavaScript :-
  
  JavaScript code placed in the head and body section in HTML documents this are called a internal JavaScript.

ex.:-

<html>
<head>
        <script type="text/javascript">
                             javascript code
        </script>
</head>
<body>
            <script type="text/javasript">
                                          javascript code 
            </script>
</body>
</html>




2.External JavaScript :-


As you begin to work more extensively with JavaScript , you will be likely to find that there are cases where you are reusing identical JavaScript code on multiple pages of a sites

You are note restricted to be maintaining identical code in multiple HTML files. The script tag provides a mechanism to allow you to store JavaScript in an external file and then include it into your HTML files.

Here is an example to show how you can include an external JavaScript file in
your HTML code using script tag and its src attribute.




<html>
<head>
            <script type="text/javascript" src="file.js"> 
            </script>
</head>
<body>


</body>
</html>
    

No comments:

Post a Comment