Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

A very common cause of strange behavior in scripts comes from not using the "==" comparison correctly. This simple script demonstrates a very common and time wasting scripting problem: 
var X =

     var X = 1;

...


alert ("X is " + X);
if (X = 2)
{
   alert("X is 2");
}

...

If you execute this script this first alert message will show X is 1 and the second will show shows X is 2 … which is not possible.
The cause of this problem is of course that the if statement should have been 
if

     if (X == 2)
{
   alert("X is 2");
}