Strange behavior in scripts

RAMP-TS

Strange behavior in scripts 

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 = 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 (X == 2)

{

   alert("X is 2");

}