Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Javascript - Variables

Javascript variables uses to contain information. 

Syntax: 
var <name> = <value>

Ex: 
var No1 = 5;
var No2 = 10;
var total = No1 + No2;

Javascript Variable names;
1. must begins with a letter
2. can begins with $ or _
3. are case sensitive

How to define a Javascript Variable

1. Method 01
    var carName = "Toyota"

2. Method 02
    var carName;
    carName = "Toyota";


JavaScript Basic


  • We use <script> tag to insert javascript to a HTML document. Inside the script tag we use Type attribute to define the scripting language. It is optional to use the attribute of Language to define the script language.

  • JavaScript can be put under the header segment or body segment. Something needed to do before loading the page, you can define under header segment.
    Syntax: 
    <script language = "javascript" type = "text/javascript" >
    ------
    </script>

  • Opening tag of <script language = "javascript" type = "text/javascript" > and the closing tag of </script> tells where the JavaScript starts and ends.

  • To write some output to the HTML body we use standard JavaScript command of document.write() 
    Ex:
    <script language = "javascript" type = "text/javascript" >
    document.write("Hello!.. This is my 1st JavaScript Program");
    </script>


JavaScript


What is Java Script?
  • Introduced in 1996 by the Netscape team and release with Netscape 2.0
  • Javascript was design to add interactivity to HTML documents
  • Javascript is a scripting language specially a client side scripting language
  • Javascript is usually embedded directly into HTML documents
  • Javascript is a dynamic type programming Language
  • Javascript supports all the browsers namely Internet Explorer, Mozilla Firefox, Google Chrome, Opera & Safari.
  • Javascript can be used to form verification
  • Javascript can be used to Basic document intelligence that can embed a base level of intelligence to the document by linking elements to script via events
  • Javascript can be used to document animation and automation
  • Everyone can be used to react to events
  • The standard was approved as an International ISO (ISO/IEC 16262) standard in 1998.
Syntax: 
<script language = "javascript" type = "text/javascript"
------
</script>

* Some earlier browsers are not supporting for Javascript  & display the code as body content. To prevent that, include javascript inside the HTML comment tag. Javascript supporting browsers interpret following & others hiding the code.
Ex: 
<script language = "javascript" type = "text/javascript">

<!--
document.write("This phrase inside the HTML Comment");
-->
</script>