|
|
Comparing JavaScript StringsIf you use JavaScript within your AssemblyLines, you might experience some strange behavior when comparing strings. This is due to some not-always-intuitive behavior of JavaScript. To make a long story short, you might want to append the empty string "" whenever comparing strings in JavaScript. If you want to know why, read on. Below is a little table that shows the behavior when comparing different variables. All constants, string literals and JavaScript string objects below will contain the characters "test": If the value is False, you might want to understand why.
This is important to understand because the Entry objects all have a getString() method that returns an Object, not a string. Think of it as corresponding to doing a new String(). So assuming var w = system.newEntry(); will give you
So unless you understand the type of the string objects you use, you might want to always play it safe by adding a "" before comparing. WarningThe statements n = null; will in JavaScript make the variable n contain the string "null". So if you have two null variables, n1 and n2
So when forcing a 'cast' by adding "", do it on both side of the compare operand. But you math teacher probably already told you something like this :-)
|
|
|