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 6796255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:26:42+00:00 2026-05-26T18:26:42+00:00

Are there any side effects if i convert a string to a number like

  • 0

Are there any side effects if i convert a string to a number like below..

var numb=str*1;

If I check with the below code it says this is a number..

var str="123";
str=str*1;
if(!isNaN(str))
{
  alert('Hello');   
}

Please let me know if there are any concerns in using this method..

  • 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-26T18:26:43+00:00Added an answer on May 26, 2026 at 6:26 pm

    When you use parseFloat, or parseInt, the conversion is less strict. 1b5 -> 1.

    Using 1*number or +number to convert will result in NaN when the input is not valid number. Though unlike parseInt, floating point numbers will be parsed correctly.

    Table covering all possible relevant options.

    //Variables    // parseInt  parseFloat  + 1* /1   ~~ |0 ^1 >>0  >>>0
    var a = '123,',//   123        123       NaN       0     & <<0   0
        b = '1.e3',//   1          1000      1000      1000          1000
        c = '1.21',//   1          1.21      1.21      1             1
        d = '0020',//   16         20        20        20            20
        e = '0x10',//   16         0         16        16            16
        f = '3e9', //   3          3000000000  <--    -1294967296    3000000000
        g = '3e10',//   3          30000000000 <--    -64771072      4230196224
        h = 3e25  ,//   3          3e+25     3e+25     0             0
        i = '3e25',//   3          3e+25     3e+25     0             0
        j = 'a123',//   NaN        NaN       NaN       0             0
        k = '  1 ',//   1          1         1         1             1
        l = '    ',//   NaN        NaN       0         0             0
        m = '.1  ',//   NaN        0.1       0.1       1             1
        n = '1.  ',//   1          1         1         1             1
        o = '1e999',//  1          Infinity  Infinity  0             0
        p = '1e-999',// 1          0         0         0             0
        q = false ,//   NaN        NaN       0         0             0
        r = void 0,//   NaN        NaN       NaN       0             0
        _ = function(){return 1;}, /* Function _ used below */
        s={valueOf:_},//NaN        NaN       1         1             1
        t={toString:_};// 1        1         1         1             1
    
    // Intervals: (-1e+20, +1e20)  (-∞,+∞)   (-∞,+∞)   (-2³¹,+2³¹)   [0, 2³²)
    // In FF9 and Chrome 17, Infinity === Math.pow(2, 1024), approx. 1.7976e+308
    // In FF9 and Chrome 17, bitwise operators always return 0 after about ±1e+25
    

    Notes on number conversion methods:

    • The number conversion always fail if the first character, after trimming white-space, is not a number.
    • parseInt returns an integer representation of the first argument. When the radix (second argument) is omitted, the radix depends on the given input.
      0_ = octal (base-8), 0x_ = hexadecimal (base-16). Default: base-10.
      parseInt ignores any non-digit characters, even if the argument was actually a number: See h, i.
      To avoid unexpected results, always specify the radix, usually 10: parseInt(number, 10).
    • parseFloat is the most tolerant converter. It always interpret input as base-10, regardless of the prefix (unlike parseInt). For the exact parsing rules, see here.

      The following methods will always fail to return a meaningful value if the string contains any non-number characters. (valid examples: 1.e+0 .1e-1)

    • +n, 1*n, n*1, n/1 and Number(n) are equivalent.
    • ~~n, 0|n, n|0, n^1, 1^n, n&n, n<<0 and n>>0 are equivalent. These are signed bitwise operations, and will always return a numeric value (zero instead of NaN).
    • n>>>0 is also a bitwise operation, but does not reserve a sign bit. Consequently, only positive numbers can be represented, and the upper bound is 232 instead of 231.
    • When passed an object, parseFloat and parseInt will only look at the .toString() method. The other methods first look for .valueOf(), then .toString(). See q – t.
    • NaN, “Not A Number”:
      typeof NaN === 'number'
      NaN !== NaN. Because of this awkwardness, use isNaN() to check whether a value is NaN.

    When to use which method?

    • parseFloat( x ) when you want to get as much numeric results as possible (for a given string).
    • parseFloat( (x+'').replace(/^[^0-9.-]+/,'') ) when you want even more numeric results.
    • parseInt( x, 10 ) if you want to get integers.
    • +x, 1*x .. if you’re only concerned about getting true numeric values of a object, rejecting any invalid numbers (as NaN).
    • ~~, 0| .. if you want to always get a numeric result (zero for invalid).
    • >>>0 if negative numbers do not exists.
      The last two methods have a limited range. Have a look at the footer of the table.

    The shortest way to test whether a given parameter is a real number is explained at this answer:

    function isNumber(n) {
        return typeof n == 'number' && !isNaN(n - n);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering if there are any SEO side effects if I put my
If a Task is created using the LongRunning option are there any side effects
Are there any unclear side effects to throwing an exception from within a synchronized
Are there any side effects to changing a class hierarchy's ancestor from TObject to
Are there any UI widgets available to the python side of Google App Engine?
Are there are any rules for when to use Client-Side validation and when to
Is there any way to check whether a file is locked without using a
Is there any query which can return me the number of revisions made to
Generally, a get request is not meant to have any side-effects. However many sites
Is there any practical difference in terms of effects on the component model between:

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.