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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:53:56+00:00 2026-05-27T02:53:56+00:00

Suppose I have a JavaScript function. and it contain a variable x; function A(){

  • 0

Suppose I have a JavaScript function. and it contain a variable x;

function A(){
   var x = 12+34;
}

Is it possible to access x from outside function x?

  • 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-27T02:53:57+00:00Added an answer on May 27, 2026 at 2:53 am

    No, the ability to do so would not make any sense. Suppose we changed your function slightly and called it 3 times:

    function x(n){
       var x = n+34;
    }
    
    x(1), x(2), x(3);
    

    At this point, the function has run 3 times, so the variable x has been created 3 times — which x would you expect to be able to access? Then there’s garbage collection; how could references and data be cleared from memory if the browser had to keep variables alive once they’re no longer in scope?

    If you want to, you can do something like this:

    function x() {
        x.x = 12+34;
    }
    x();
    

    or, if the variable will be static/constant as you have it

    function x() { }
    x.x = 12+34;
    

    or finally, as others have pointed out, by declaring x under a different name outside of the function’s scope:

    var y;
    function x() {
        y = 12+34;
    }
    x();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have javascript within ASP.NET UserControl: function setValue(DataItem) { var selectedDate = DataItem.getMember('DomainNameKey').get_object();
Suppose I have a long javascript function such as function test() { var x;
Suppose I have JavaScript code like myClass = function(){ function doSomething(){ alert(this); // this1
suppose i am getting HTML text in my JavaScript function as var TEMP= result.data;
I have an external JavaScript that contains: function random_imglink(){ var myimages=new Array() myimages[1]="http://sevir.sitegoz.com/jchs/Banner1.png" myimages[2]="http://sevir.sitegoz.com/jchs/banner2.png"
I have a problem with a javascript global variable, let's suppose I have the
Suppose I have a class module clsMyClass with an object as a member variable.
Consider the following Javascript function (1): function setData(domElement) { domElement.myDataProperty = { 'suppose': 'this',
I have a javascript file that reads another file which may contain javascript fragments
Suppose I have this code : <head> <script type=text/javascript> func1(); </script> <script type=text/javascript src=jquery.js></script>

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.