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

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

Expand Messages
  • Rob Richardson
    Feb 3, 2011
      This seems clearer:

      a = "4";
      if (isNaN(Number(a)) {

      b = "4a";
      if (isNaN(Number(b)) {

      ... but as soon as you call Number(..), you have already converted it to a
      number. (see http://www.w3schools.com/jsref/jsref_Number.asp) Thus, in the
      example ("if (Number(a) === Number(a)) {") you've actually converted it to a
      number twice but still don't have a number var. If you are going to do math
      with it, you'll need to convert it a third time.

      I'd recommend something like this:

      a = "4";
      aN = Number(a);
      if (isNaN(aN)) {

      ... which is basically what Luke said.


      -----Original Message-----
      From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On
      Behalf Of Cheney, Edward A SSG RES USAR USARC
      Sent: Thursday, February 03, 2011 10:16 AM
      To: jslint_com@yahoogroups.com
      Subject: Re: [jslint] Suggestion for error (UNCLASSIFIED)

      Classification: UNCLASSIFIED

      > if (a !== a) {
      > }
      > if (a === a) {
      > }

      I use that logic to determine if a value, regardless of type, can become a
      number type.

      For instance:

      a = "4";
      if (Number(a) === Number(a)) // true

      b "4a";
      if (Number(b) === Number(b)) // false, because NaN does not equal NaN as
      they are type number, but are not a valid number.

      Further more you could have a comparison of functions where a number type is
      a = function (x) {
      return (Number(x) + 3);
      if (a(4) === a("4")) // true

      Austin Cheney, CISSP

      Classification: UNCLASSIFIED
    • Show all 5 messages in this topic