Click to See Complete Forum and Search --> : what is variable?


Gopinath
06-25-2003, 04:01 AM
what is variable and how it works?

SlankenOgen
06-25-2003, 06:04 AM
A variable has two parts - a name and a value.

When you declare a variable you might use-
var x = 10;

'x' is the name and 10 is its value.

That means you are creating a variable [hence the keyword 'var'] and giving it a value of 10.

The name 'x' represents a block of memory in your computer and the value 10 is stored in that part of memory.

If you write x = x + 1;

You are asking the computer to go to the memory location, which you have named, or labeled as 'x', and increase the value to 11.

Normally you declare/create a variable with 'var'. From there on it exists and you can reference it and change it just by using its name.

~mgb