Programming basics
Variables and data types
Variables are like containers or boxes to keep the necessary information in your program. Imagine that you have a jar and want to keep jam in it. You may place there apricot jam, cherry compote, blueberry spread. If you wish – you may keep pickled cucumbers or something else. You may fill it with milk or rice. It may be empty. You used to call it "big green jar" in your family.
In your garage you have three boxes. There are numbers on the tops – "Box1", "Box2", "Box 3". You also keep various stuff in them.
If you had a computer model of your household you could imagine that "bigGreenJar" and "box1" are names of your variables. And "blueberry jam" and "old black shoes" are values of bigGreenJar and box1 variables respectively.
In ActionScript it could look simple like that
clientAccNum = "S238993-2232";where clientAccNum is a variable name and "S238993-2232" is it's value. Semicolon makes end of the line in ActionScript.
Programmer may reassign value of the variable and make it … let's say "C32443-5938". Old value disappear and new is kept.
Along with names and values variables have. data types .
Given our example you may see that it's impossible to put a dog or an armchair into bigGreenJar and it's also impossible to keep gasoline in box1.
The same is with computer variables. Some of them are capable to keep integer (whole) numbers, some –decimal point numbers, some – text strings, some – larger objects, for example buttons. Data types are not declared explicitly in scripting languages, but if you created a variable varA and assign a String to it – it may be a discrepancy if the next time you will try to place a number there. Variable may "remember" the data type.
Also variables have a scope.
It means that if they first appear inside certain code fragment (function) they may expire after this code fragment is exited.
If you simply write variable name like
a = 33;this variable becomes global. If you declare a variable like
var a = 33;it becomes local.