Programming data have to be cached frequently. For this we use variables.
Every variable is addressed by its name. A variable name consists of letters, numbers and the underscore
_toolinfy_. Invalid variable names would be:
1toolinfy (first character is a number),
tool infy (space) and
To assign a value to a variable you use the equal sign
=. On the right side you define the value, on the left side you specify the variable name.
There are different types of variables. The american number system is used for the numeric values, which means that you use decimal points.
one = 1; minus_twenty = 20; one_to_five = 12345;
A string is surrounded by quotation marks - either single quotes (
'') or double quotes (
""). It doesn't matter whether you use single or double. It's only important that you end a string with the same type of quotes that you started it with.
website_name = "toolinfy"; html = "HyperText Markup Language";
The two quote types are useful when one of those two types is part of a string. For example you mustn't use:
text = 'That's great!';
but you can use:
text = "That's great!";
\. The following examples are valid variables:
text = " \"Woooohoooo\" "; text = 'That\'s cool!';
If a backlash should be part of a string you have to escape it with another backslash.
text = "This is one backslash: \\";
Sometimes we're not interested in a number or a string.
We simply want to know whether something is
These values are called Boolean values.
is4anevennumber = true; is3000aleapyear = false;
As you can see, we can assign a value to a variable using an equal sign.
A variable-name also can be used repeatedly and you can assign a value to a variable multiple times.
In practice you often see the keyword
var before the first use of the variable.
This keyword is used for the initialization of a variable. First of all it helps you to see which variable has already been
declared and which not.
Note that the keyword
var can only be used once per variable.
The following example is right:
var count = 1; count = 2;
The following code would be wrong:
var count = 1; var count = 2;
The reason is that a variable is re-initialized when
var is used.
This means that the old variable is deleted and a new one is created.
The use of
var is needless when a variable already exists.
Continue to part 5