Difference between revisions of "Variables"

From CodeStuff
Jump to: navigation, search
 
Line 3: Line 3:
 
print("the value of x is:"+x);
 
print("the value of x is:"+x);
 
</edcode>
 
</edcode>
 +
  
 
Putting a value into a variable is easy,  just use <tt>=</tt>.  
 
Putting a value into a variable is easy,  just use <tt>=</tt>.  
Line 9: Line 10:
 
print("the value of p is:"+p);
 
print("the value of p is:"+p);
 
</edcode>
 
</edcode>
 +
  
 
You can make a variable and give it a value all in one line
 
You can make a variable and give it a value all in one line
Line 14: Line 16:
 
print("the value of variableName is:"+variableName);
 
print("the value of variableName is:"+variableName);
 
</edcode>
 
</edcode>
 +
  
 
Using JavaScript, you can place any value into a variable,  
 
Using JavaScript, you can place any value into a variable,  
Line 19: Line 22:
 
print("the value of w is:"+w);
 
print("the value of w is:"+w);
 
</edcode>
 
</edcode>
 +
  
 
When I said "any value" I really meant it.  Watch this one.
 
When I said "any value" I really meant it.  Watch this one.
Line 25: Line 29:
 
z("the value of z is:"+z);
 
z("the value of z is:"+z);
 
</edcode>
 
</edcode>
 +
  
 
Changing the value of a variable is as simple as putting another variable into it.
 
Changing the value of a variable is as simple as putting another variable into it.
Line 36: Line 41:
 
print("the value of w is:"+w);
 
print("the value of w is:"+w);
 
</edcode>
 
</edcode>
 +
  
 
Because variable can change value you can use them to hold information about what the program is doing right now.
 
Because variable can change value you can use them to hold information about what the program is doing right now.

Latest revision as of 08:02, 2 February 2012

Variables are used in programming to hold values. In JavaScript you make a variable with var.


Putting a value into a variable is easy, just use =.


You can make a variable and give it a value all in one line


Using JavaScript, you can place any value into a variable,


When I said "any value" I really meant it. Watch this one.


Changing the value of a variable is as simple as putting another variable into it.


Because variable can change value you can use them to hold information about what the program is doing right now. For example you can use them to count how many times the program has done something.