Loading ...
Sorry, an error occurred while loading the content.

1893RE: [jslint] Suggestion for error (UNCLASSIFIED)

Expand Messages
  • Cheney, Edward A SSG RES USAR USARC
    Feb 3, 2011
      Classification: UNCLASSIFIED
      > ... but as soon as you call Number(..), you have already converted it to a

      That is only partially accurate. You do perform a conversion every time you use Number() or String(), but as long you do assign the responses of those function back onto the variable you are testing the conversion dies with the test. For instance:

      a = "4";
      if (Number(a) === a) // false, because variable a is still assigned a value of string 4 and has not been reassigned.

      Fortunately, this matter of assignment versus type is simple with strings and numbers. Assignment is a bit more complicated when dealing with arrays and object literals. For instance:

      a = ["a","b","c"];
      b = a; // this does not do what you might expect, instead b is now a pointer to the contents of variable "a".

      If you want to clone array "a" into array "b" you would have to do something like the following:
      a = ["a", "b", "c"];
      b = [].concat(a);

      The moral of this story is that testing for conversion is not the same as an assignment and do not expect assignment to represent a uniquely assigned and wholly contained value.

      Austin Cheney, CISSP
      Classification: UNCLASSIFIED
    • Show all 5 messages in this topic