Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:54:35+00:00 2026-05-26T07:54:35+00:00

Number function > var x = new Number(5) > x === 5 false >

  • 0

Number function

> var x = new Number(5)
> x === 5
false
> Number(x) === 5
true

valueOf method

> var y = new Number(5)
> y === 5
false
> y.valueOf() === 5
true

Which is the preferred option? Are there benefits to using one over the other?

For the record, I’m dealing with this within a method on Number.prototype, where I can be sure that this is always a Number object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:54:36+00:00Added an answer on May 26, 2026 at 7:54 am

    I would think the valueOf is preferred, since Number conversion is meant to be used with values that are not already Number objects, but moreover – Number(x) will call valueOf method on x,
    so essentially, you’d add an unnecessary sugar/overhead, where valueOf is a perfectly accepted way of receiving a primitive representation of an object (Number in your case).

    As a side note:

    For the record, I’m dealing with this within a method on
    Number.prototype, where I can be sure that this is always a Number
    object.

    this is not correct as there is always a possibility that someone will do something like this:

    Number.prototype.test = function()
        {
            console.log(this);
        }
    
    var x = new Number(10);
    x.test();
    
    var foo = x.test;
    foo();
    

    would of course provide:

    Number
    DOMWindow
    

    as output. It’s for you to decide whether you want to defend against it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just curious: 4 instanceof Number => false new Number(4) instanceof Number => true? Why
var x= 1; Number.prototype.test = function () { return this }; x.test() === x.test()
I have the following bit of code: protected function onEnterFrame(e:Event):void { var diff:Number; //
I'm using a custom random number function rand48 in CUDA. The function does not
Using the javascript function function squareIt(number) { return number * number; } When given
I am trying to code a random number generation function in embedded C where
In a simple html page I have: <SCRIPT> function Clicker(number){ if (number == 1)
My function takes an array of ifstream ofjects and the number of ifstream objects
uniqid() function returns a 13 digits long hexadecimal number. According to the spec in
I have a number of iframes calling a function in my main page. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.