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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:26:33+00:00 2026-05-23T23:26:33+00:00

I am currently trying to learn Javascript and understand that functions are one of

  • 0

I am currently trying to learn Javascript and understand that functions are one of the most important aspects of the language but I have to say Im finding it very hard to understand them especially when different parameters are being used here there and everywhere.

I have been looking at this code which I read in another stack overflow post regarding closure and cant understand how 16 is alerted, I have used console.log to work out what value is being used at each point and seem to get a total of 17, could someone possibly explain?

function foo(x) {
 // console.log(x); = 2    
 var tmp = 3;
 return function (y) {
  // console.log(y); = 10
  alert(x + y + (++tmp));
  // console.log(++tmp); = 5?
 }
}
var bar = foo(2);
bar(10);

If anyone can offer any wisdom about functions that might make things start to make sense for me it would be really appreciated.

Kyle

  • 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-23T23:26:34+00:00Added an answer on May 23, 2026 at 11:26 pm

    The alert() command really pops up 16.

    ++tmp is preincrement statement – first, it increments the value (from 3 to 4) and then continues with execution of the line.

    So 2 + 10 + 4 is passed to the alert().

    The console.log(++tmp) below the alert logs 5, because the tmp variable is incremented again, from 4 to 5.

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

Sidebar

Related Questions

I am currently trying to learn all new features of C#3.0. I have found
I am currently trying to learn C and I have come to a problem
I'm currently trying to learn Ruby and I'm trying to understand more about what
I'm currently trying to learn HTML and Java EE Servlet programming. I have an
I'm currently trying to learn OO Javascript so I can write some cleaner code.
I don't really have a real world problem, yet, but I'm trying to learn
I'm trying to learn how to develop a j2ee web application but is currently
I am currently trying to learn JavaScript and in a particular excercise, I am
I currently trying to find a solution, how to ensure that a test fails
I'm just starting to learn Javascript; I do however have experience in programming using

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.