Untitled Document



 Introduction to HTML
 Structure of HTML
 Creating First HTML  Document
 Building Your HTML  Document
 Tables
 Frames
 Including Images into  Document
 Including Multimedia
 Developing HTML  FORMS
 Using Style Sheet
 Understanding URLs
 Using JavaScript
 Introducing JavaScript
   Using JavaScript
 Introducing to  JavaScript
   What is JavaScript?
 Why should you use  Java Script?
 Structure of a  JavaScript
   Syntax of JavaScript
 JavaScript
 Statements
 
 Statements
 Blocks
 
 Blocks
 Comments
 
   Comments
 Single-Line  Comments
 Multiline Comments
 Data
 
   Data
   Strings
   Numbers
   Boolean
 Null
 Expressions
 
   Expressions
   Numeric Expressions
 Logical Expressions
 Variables
 
   Variables
 Defining and Naming  Variables
 Changing the Value  of a Variable
 Functions
 
   Functions
   Built-in Functions
 User-Defined  Functions
 Returning Values  from Function
 Flow Control
 
   Flow Control
   If and if ....else
   If Statement
   If...else Statement
   IF Statement
   Looping Statements
   For Loops
   While Loops
   WHILE Statement
   Switch Statement
   Break Statement
 Continue Statement
 Objects
 
   Objects
   Methods
   Properties
   Built-in Objects
 User-defined Objects
 Arrays
 
 Arrays
 Event Handlers
 
   Event Handlers
 onMouseOver,  onMouseOut Events
 onClick, onChange  Events Handlers
 Using the onSubmit  Event Handler
 Introduction to Cookies
 
 Introduction to  Cookies
   Sessions Cookies
 Persistent Cookies
 Using Java

Copyrights : Layout Galaxy All Rights Reserved
No part of this tutorial may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, electrostatic, magnetic tape, mechanical or otherwise, without prior permission in writing from Layout Galaxy.




  Using JavaScript > Variables

  Variables

Having data and expressions is fine, but it's not of much use if you cannot store it some where. Variables enable you to define places to store this data. Think of a variable as a storage container. It always contains something, but what it contains can change over time.

  Defining and Naming Variables

It's extremely simple to define a variable in JavaScript. Think of a name for the variable that you want to define and then put var before it. You can either initialise a value or create a variable without an initial value. If you create a variable using second case then you should be careful not to access the variable before it has had a value placed in it.

Rules to follow while creating a variables:

The variables name cannot be reserved word.
The first character in the name must be an alphabetic or Underscores(_)
The first character in the variable name can be alphabetic, letters, number or underscores.

Valid variables names: Invalid variables names:
Varx_location; Var99baloons: // Violates rule 2
Var_location; Var eggsSbacon: // Violates rule 3
Var ven 32; Var $ ven; // Violates rule 4
Var question_22; Var package; // Violates rule 1

  Changing the Value of a Variable

To give a variable a new value after it is created, the assignment operator (=) is used. The variable name is listed on the left-hand side of the statement, and an expression containing the value it has to be assigned is listed on the right-hand side of the statement.

Example :

myvalue = 10;
myvalue = true;
myvalue = "Football";

Back Next


Copyrights : Layout Galaxy All Rights Reserved
No part of this tutorial may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, electrostatic, magnetic tape, mechanical or otherwise, without prior permission in writing from Layout Galaxy.




17, Vadsarvala Nivas, 65-A, J. Nehru Road, Mulund (W), Mumbai - 400 080 INDIA
Tel : 91-22-25795588, 91-22-25780444 Fax : 91-22-25793397
Email : ionline@vsnl.com
© Image Online 2001-2003