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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:38:09+00:00 2026-05-27T11:38:09+00:00

var str = ‘internet’; performAction(function(str) { console.log(str); }); Is there a problem with having

  • 0
var str = 'internet';

performAction(function(str) {
    console.log(str);
});

Is there a problem with having a private variable str and also having a callback function with a parameter of the same name?

Thanks!

  • 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-27T11:38:10+00:00Added an answer on May 27, 2026 at 11:38 am

    This is just a standard scope situation – the fact that it is an anonymous function expression passed as a parameter to another function doesn’t matter. Note that within your performAction() function (which you don’t show) it will not have any access to the str that is the parameter of the callback function – if performAction() references str it will get the global “internet” variable (or its own local str if defined).

    A function’s parameters are, for scope purposes, the same as that function’s local variables, which means they mask other variables of the same name from outer scope – but variables with different names can still be accessed even if defined in a wider scope.

    Where it could get confusing is if you do something like this:

    var str = "internet";
    
    (function(str) {
      console.log(str); // "internet"
      str = "local param";
      console.log(str); // "local param"
    })(str);
    
    console.log(str); // "internet"
    

    In that case I have a function with a parameter called str but when I call it I’m passing in a different str. Note that changing str within that function only changes the local str, not the global one. They are two different variables…

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

Sidebar

Related Questions

var str = This is a string; var thing = str.replace(string,thing); console.log( str )
How do i pass a variable in the xmlhttp.send function var str = hello
For the following JavaScript: function EscapedString(str) { var obj = document.createElement(span); obj.innerHTML = str;
input is a string (var str) something like this: <<hello there//abcd//1234>> I want to
is there a way to deserialize strings to objects in actionscript: i.e. var str:String
I have the following code: $('.getcode').click(function () { $('textarea').val(); var str = []; $('#group-wrap
this code always return 0: function myFunc() { var str = 0; JQuery.ajax({ type:
I am having trouble using the var str in an if statement. I know
Alright, here's my current test function: function make_void( str ) { var str_arr =
$(document).ready(function() { redo(1); $(select).change(function () { var str = ; $(select option:selected).each(function () {

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.