Tuesday 7, September 2010
      Home       Tutorials       Free Ebooks       Free Scripts       Tech News       Articles       About Us

Variables

JavaScript Variables
As with algebra, JavaScript variables are used to hold values or expressions.
A variable can have a short name, like x, or a more descriptive name, like carname.
Rules for JavaScript variable names:

  • Variable names are case sensitive (y and Y are two different variables)
  • Variable names must begin with a letter or the underscore character

Note: Because JavaScript is case-sensitive, variable names are case-sensitive.

A variable is a place holder in your computer's memory for information that can change.  This place in memory is given a name in JavaScript so that you can easily refer to it. Declaring a variable is easy.  All you have to do is precede the variable name with the JavaScript reserved word var as follows:

var myVariable

Once the variable is declared, you can set it to any one of the values shown in the above table. Here is an example:

myVariable = 5

Later on in the program you can change its value to something different:

myVariable = 33

You can even change its type by simply assigning it a different type of value. For instance our variable was originally assigned a number. We can make it a string later in the program by simply assigning it one as follows:

myVariable = "this is a string"

Note that the variables in some other languages, such a C, are strongly typed and you are not allowed to randomly change the variable's type as we did here.

You can initialize a variable and assign it a value at the same time as follows:

var myVariable = "JavaScript is cool"

This is method that you will probably use most of the time to declare and initialize your variables.

You can even leave out the var keyword as follows:

myVariable = "this is not too cool"

You will note that the variable name myVariable contains two words with the first letter of the second word capitalized. It is common practice in JavaScript to use small letters for variable names and to capitalize the first letter of every new word starting with the second word. Also note that there is no space between the two words.

   
 
JavaScript Tutorial
 
  Introduction
Introduction
  Object Oriented Programming
Object Oriented Programming
  How to
How to
  Where use JavaScript
Where use JavaScript
  Variables
Variables
  Operators
Operators
  if Statement
if Statement
  Switch Statement
Switch Statement
  Functions
Functions
  for Loop
for Loop
  while Loop
while Loop
  Popup Boxes
Popup Boxes
  break and continue Statements
break and continue Statements
  Events
Events
  Date and Time Object
Date and Time Object
  Special Characters
Special Characters
 
 
 
Web Designing Tutorials
  HTML Tutorial
HTML Tutorial
  DHTML Tutorial
DHTML  Tutorial
  CSS Tutorial
CSS Tutorial
  XHTML Tutorial
XHTML Tutorial
 
Programming Languages Tutorials
  C Language Tutorial
C Language Tutorial
  C++ Tutorial
C++ Tutorial
  Java Language Tutorial
Java Language Tutorial
  Data Structure Theory Tutorial
Data Structure Theory Tutorial
 
Server Side Scripting Tutorials
  PHP Tutorial
PHP Tutorial
  SQL Tutorial
SQL Tutorial
 
Client Side Scripting Tutorials
  JavaScript Tutorial
JavaScript Tutorial
  VBScript Tutorial
VBScript Tutorial
 
 
 
POPULAR E-BOOKS
 
Download Save 100 s on Your Phone Bill The Savvy Consumer s Guide to Voip  Ebook Save 100 s on Your Phone Bill The Savvy Consumer s Guide to Voip
   
Download Enhance Your Financial Intelligence Ebook Enhance Your Financial Intelligence
   
Download Secrets to become a Super Affiliate Ebook Secrets to become a Super Affiliate
   
Download Income Plan Ebook Income Plan
   
Download Pay Per Click Marketing Guide Ebook Pay Per Click Marketing Guide
   
Technology News      
Studiesinn.com © 2010 All Rights Reserved.