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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:05:11+00:00 2026-05-25T11:05:11+00:00

Why is 100 being logged here instead of 101? function myFunction() { var i=100;

  • 0

Why is 100 being logged here instead of 101?

function myFunction() {
   var i=100;
   function f() {
      return i++;
   }
   return f();
};
var X = myFunction();
console.log(X); 

http://jsfiddle.net/PhillipSenn/8fqyh/

  • 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-25T11:05:12+00:00Added an answer on May 25, 2026 at 11:05 am

    Because f() returns the value of i before it is incremented. Use pre-increment (++i) if you want the value after it is incremented.

    Also, it’s a bit odd to declare f() for no other purpose than to immediately call it. I think what you intended was to return a function that increments i and returns the new value each time it is called. To achieve this, simply return the function, then call console.log(X()) to invoke f() and log the incremented value:

    function myFunction() {
       var i=100;
       return function() { return i++; }
    };
    var X = myFunction();
    console.log(X());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page being loaded with jQuery. The initial load includes 100 records
A more convoluted example of this question is here: child div height of 100%
I am rendering 100 events in FullCalendar using $('#CalendarPlugin').fullCalendar('renderEvent', {} ); being called 100
Page: http://www.visitherefordshire.net/news In Internet Explorer 7 and Opera 9.6, the text is running outside
Situation: I've got a SVN repository with lets say 100 revisions, rev. 100 being
100['toString'] //does not fail 100.toString //fails why? 100.toString is not same as 100.toString() .
100%I'm modifying an older website for a client that uses Ext-JS 1.1 and I'm
Is a GUID unique 100% of the time? Will it stay unique over multiple
While there are 100 ways to solve the conversion problem, I am focusing on
I need to manipulate 100,000 - 200,000 records. I am thinking of using LINQ

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.