shadowline
JavaScript Basics << Variables >> Events
Many JavaScripts deal with variables. This is where you take a word or letter and assign a value to it. The value can be either numbers or words. To think of it in physical terms, imagine a box with a label stuck on it and there is a piece of paper with a name or number written on it inside the box. The labeled box is a variable, and the name or number on the paper is the value.

var Z = X + Y

If X=1 and Y=2 then Z=3.

Look horribly familiar? It's the stuff you learn in school and think to yourself "When will I EVER need to know algebra in real life ?". Well... here it is.

You can use strings (regular text) instead of numbers in these equations too. Or a number and a string.

"This is " + "HTMlite."
"HTMlite " + 99
  This is HTMlite.
HTMlite 99

Other than the usual assignment operators + - / * = you can use JavaScript to compare two or more variables with each other. That is, it takes two values and compares them to each other. Here is a list of the different types of comparisons there are :

X == Y
X != Y
X > Y
X >= Y
X < Y
X <= Y
X && Y
X || Y
!X
  True if X and Y are equal.
True if X and Y are not equal.
True if X is greater than Y.
True if X is greater than or equal to Y.
True if X is less than Y.
True if X is less than or equal to Y.
True if X and Y are true values.
True if X or Y have a true value.
True if X has a false value.

As stated before, part of having a numeric value in variables lets you use regular math expressions on them like so...
X += Y
X -= Y
X *= Y
X /= Y
X %= Y
  X = X + Y
X = X - Y
X = X * Y
X = X / Y
X = X % Y
JavaScript Basics << Variables >> Events
shadow

Advertise in the banner along the top, Click here!

Valid XHTML 1.0 Transitional Valid CSS! Text Link Ads
shadow
shadow