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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T01:03:44+00:00 2026-06-19T01:03:44+00:00

I have this code: var boo = 123123; I want to convert that number

  • 0

I have this code:

var boo = 123123;

I want to convert that number to string and conact string is faster than native JavaScript .toString():

Faster:

var foo = boo + ""; 

Slower:

var foo = boo.toString(); 

jsPerf: http://jsperf.com/concat-string-vs-tostring

Why .toString() is slower than concating empty character? And finally I want to know is that a correct approach to use + "" technique instead of .toString()?

  • 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-06-19T01:03:45+00:00Added an answer on June 19, 2026 at 1:03 am

    Results will vary depends on javascript engine used. On chrome one I’m getting the same results as Afshin.

    So why actually one is slower than another? It’s because on toString there will be one more call to C functions inside V8. You can try next to see that by yourself:

    • Open empty tab in chrome(to avoid any side effects from already opened pages)
    • Open Developers Tools
    • Open Profiles tab and start new profile
    • Go to Console tab and insert script1 script, press enter.
    • Go to Profile again and stop profiling
    • Repeat the same with script2

    • script 1: var boo = 123123; var foo = boo + "";

    • script 2: var boo = 123123; var foo = boo.toString();

    In my case first will result in next stacktrace:

      InjectedScript.evaluate
        InjectedScript._evaluateAndWrap
    

    while second one:

      InjectedScript.evaluate
        InjectedScript._evaluateAndWrap
          InjectedScript._evaluateOn
            evaluate
    

    I think it’s more has to do with engine internals than official js spec and probably could be optimized to use the same code path.

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

Sidebar

Related Questions

I have this code: var ExtString: string; const Extensions : array[0..4] of string =
I have this code: var sideBar = localStorage.getItem('Sidebar'); I want to check if sideBar
I have this code var UserSchema = new Schema({ Username: {type: String, index: true},
I have this code: var Date = Feb 17, 2012; How can I convert
I have this code: var query = _cityRepository.GetAll( u => u.PartitionKey == pk &
I have this code: var obj = function (i) { this.a = i; this.init
I have this code: var totalAmt=0; for (i in orders) { order=orders[i]; if (order.status
i have this code: var list = new List<int>(); for(int i=0;i<10;i++) list.Add(i); for(int i=0;i<10;i++)
I have this code: var a:Array = [ Ramsey, Tusey, Iuser,Sephora,'user', 'reseo', 'nesey', 'sela']
I have this code: var fullpath = $(this)[0].src; var a = document.createElement('a'); a.href =

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.