Announcement

Collapse
No announcement yet.

Number() data type?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Number() data type?

    When I create a number using new Number() construct, what is the resulting data type? It seems to be neither float nor int.

    I ran across this problem when I discrovered that one of my switch() statements did not work. It turned out that switch() uses strict comparison (===) internally. In other words,

    new Number(1) !== parseInt(1);
    new Number(1) !== parseFloat(1);

    So, what the heck is the data type for the Number()?

    Thanks!

  • #2
    The new operator is used to create an instance of object. I don't recall there really being a Number object built in to JS...but I could easily have missed it.

    In anycase, if it is built in using the typeof operator will give you the result of what it is.

    ie:

    debugPrintln(" Number if type: " + typeof (Number));


    Garth
    Garth

    Comment


    • #3
      Thanks, Garth!
      (wasn't aware of typeof())

      Comment

      Working...
      X