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

  • Home
  • SEARCH
  • 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 8783831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:55:46+00:00 2026-06-13T20:55:46+00:00

Can someone explain me what are the differences between those two functions below? I’m

  • 0

Can someone explain me what are the differences between those two functions below?

I’m wondering if JavaScript engines do some kind of nano-optimizations here.

function withoutVar() {                                                                                                                   
  return 'stackoverflow';                                                                                                                    
}
function withVar() {
  var result = 'stackoverflow';
  return result;
}
var a = withoutVar();
var b = withVar();  
  • 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-13T20:55:48+00:00Added an answer on June 13, 2026 at 8:55 pm

    The difference is that your function withVar causes the implementation to access the underlaying Activation Object respectively Lexical Environment Record. So technically, this function will run slower, but we are not even talking about micro optimizations, more like nano optimizations.

    Some browsers might indeed optimize that code into the direct return statement for withVar. Webkit or at least Chrome with their V8 engine are good candidates for that. Either way, again, this is entirely trivial and you should not be concerned about run-time performance here.

    JSPerf benchmark

    Difference on my machine (Chrome) is about 0.32% on ~7.000.000 calls.


    The only argument I would consider to buy on stuff like this is, that the former function works with less characters. In that way, you can optimize your filesize and reduce traffic over the wire (but even then, we would have to optimize such statements on many instances before it really comes into play)

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

Sidebar

Related Questions

Can someone explain the difference between these two, the first one is taken from
Can someone please explain the major differences between Scala, Groovy and Clojure. I know
Can someone explain to me the differences between these Certificate types shown in my
What are the differences between these 3 types of loading? Can someone explain with
Can someone explain the difference between the two? From what I have read, subscription
Can someone once and for all explain to me the difference between these two
Can someone please explain the difference between these two examples in the context of
Can someone explain the difference between the results of these two operations? Time.now -
Can someone explain the differences between a DL Reasoner like Pellet/deafult OWL Reasoner and
Can please someone explain the differences between Functor and Monad in the Scala context?

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.