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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:23:38+00:00 2026-06-02T01:23:38+00:00

var b=1; function someFunc(b) { //here } I want to be able to reference

  • 0
var b=1;

function someFunc(b) {
     //here 
}

I want to be able to reference the variable b that is defined outside the function. How can this be done in javascript?

  • 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-02T01:23:40+00:00Added an answer on June 2, 2026 at 1:23 am

    You need to access it via the global object, which is window in a browser and global in node.js for instance.

    var b=1;
    
    function someFunc(b) {
        alert( window.b ); // or console.log( global.b );
    }
    

    Why ? Well, the such called Activation Object (in ES3) or the Lexical Environment Record (ES5) will overlap the variable name b. So anytime a JS engine resolves b it’ll stop at the first occurence, which is in its own Scope.

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

Sidebar

Related Questions

var Dog = function() { var _instance = 'hello world'; return function() { console.log(this._instance);
For example: (function() { var proxied = window.eval; window.eval = function() { return proxied.apply(this,
$(function(){ $('a').each(function(){ var x=this.href; this.href=www.somesitename.com/filter+this.href; }); }); i wrote the above jQuery script to
$(.sectionHeader).click(function() { var row = $(this).parent(); while (row.next().length != 0) { row = row.next();
$(.delete).click( function() { var thesender = this; $(thesender).text(Del...); $.getJSON(ajax.php, {}, function(data) { if (data[result])
$(.eventName).click( function () { var eventId = $(this).attr('id'); var role = $(this).attr('dir'); var todo
a little misunderstanding with JQuery and JS variables. Simple example: function someFunc(){ var flag
When I want to call a function in javascript with arguments supplied from elsewhere
Can I put similar methods in an associative aray like this? var function_hold =
Consider the following code: (function() { var a = 5; var someFunc = 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.