Archive | LotusScript RSS for this section

var = != var ==

This is a public service announcement for anyone rewriting LotusScript code in Javascript (client-side or server-side) for an XPages application.

If you want to check whether your variable (x) has a value of ‘IE Stinks’, be careful to use the correct operator.

This line, will always return true in JavaScript (and not just for the obvious semantic reason):

if (x = 'IE Stinks')

This line is the correct line to use:

if (x == 'IE Stinks')

In JavaScript, the equals sign (=) is only an assignment operator, which means it assigns the value on the right to the variable on the left. Even though syntactically similar, it is a mistake to use it as a comparison operator (comparing whether one value equals another), because it will always return true.

In LotusScript, the equals sign is both a comparison operator and an assignment operator, which means we can use it in both cases. This is why it’s easy to make that mistake.

So, to recap, IE Stinks and these are the correct operators for assignment and comparison in LotusScript and JavaScript:

Assignment Comparison
LotusScript x=’IE Stinks’ if (x=’IE Stinks’)
JavaScript x=’IE Stinks’ if (x==’IE Stinks’)