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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:01:21+00:00 2026-05-23T14:01:21+00:00

function user(req,res){ var uuu = req.params.userid; processUserObject(uuu, function(user_object){ //This could take a long time…

  • 0
function user(req,res){
    var uuu = req.params.userid;
    processUserObject(uuu, function(user_object){ //This could take a long time...
        console.log(uuu); 
        res.send(JSON.stringify(user_object));
    });
};
app.get('/:userid',function(req,res){
    user(req,res);
});

First, assume that the site gets lots of hits. (thousands per second!)

When a user hits the page with his ID, will console.log(uuu) output the correct ID? What I’m worried (in regards to variable scoping) is that when person A hits the page and goes through processUserObject, it could take a long time, during which person B hits the page and changes uuu…resulting in console.log to output person B’s ID instead of person A’s ID.

Side note: I have this worry because when I was new to Node.js, I forgot to initialize some variables with var. When my site got lots of hits, my users noticed that they were getting info from other user’s hits…ouch.

  • 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-23T14:01:21+00:00Added an answer on May 23, 2026 at 2:01 pm

    Yes, console.log(uuu) will log the right value. When you say this:

    var uuu = req.params.userid;
    

    You are capturing the current value of req.params.userid in the local variable uuu and then uuu is captured by the callback closure. However, if you accidentally did this:

    uuu = req.params.userid;
    

    Then you’d be capturing the req.params.userid value in the global uuu and each of your callbacks would share the same uuu and you’d have the usual closure problem. Each of your

    function(user_object) { ... }
    

    anonymous functions are separate and distinct entities with their own separate and distinct uuu variables (given that you say var uuu rather than uuu of course).

    BTW, if you do end up with a billion requests per second the heat from your overworked CPUs will melt the walls between this world and the next thus releasing the elder gods from R’lyeh. And if that happens, uuu won’t matter at all.

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

Sidebar

Related Questions

In the following Express function: app.get('/user/:id', function(req, res){ res.send('user' + req.params.id); }); What are
I have this user defined function. public partial class UserDefinedFunctions { static int i;
app.get('/',function(req,res){ res.render('home'); // I want the template to be able to access the flash
I want to initiate a function when user finishes resizing of his browser window.
How can I get a user-defined function to re-evaluate itself based on changed data
I have a user defined function in SQL called getBuisnessDays it takes @startdate and
I'm calling a function with call_user_func_array : call_user_func_array(array($this, 'myFunction'), array('param1', 'param2', 'param3')); Everything is
I need a function that a user can just click a flash app button
Why calling a user defined function need the owner name when calling a stored
Most systems will have a user-defined function (UDF) available. Some will not. i want

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.