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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:03:13+00:00 2026-06-10T19:03:13+00:00

I was reading this article and I have some questions please: considering this code

  • 0

I was reading this article and I have some questions please:

considering this code :

1:   var a = 1;
2:   function b () {
3:       a = 10;
4:       return;
5:       function a() {}
6:   }
7:   b();
8:   alert(a);

this will alert 1. ( my question is why ? )

the article states its related to Name resolution.

Name resolutions (according to the article ) is being determined by this order:

1. Internal mechanisms of language: for example, in all scopes are available “this” and “arguments”.
2. Formal parameters: the functions can be named as the formal parameters, which scope is limited to the function body.
3. Function declarations: declared in the form of function foo() {}.
4. Variable declarations: for example, var foo;.

line #3 suppose to change the value of the global a.
but the function a(){…} have a priorty over the inside a declaration ( If i understood correctly)
and thats why is alerts 1

p.s. if i remove line #5 , it will alert 10.

In general, if a name is already defined, it will never be redefined
by another entity with the same name. That is the function declaration
has a priority over the declarations of the variable with the same
name. But this does not mean that the value of a variable assignment
does not replace the function, just its definition will be ignored.

I dont understand that part :

But this does not mean that the value of a variable assignment does
not replace the function

so 2 questions please :

  • Did I understand correctly the reason for alerting 1

  • What does the above line means ? (the misunderstood part)

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-06-10T19:03:15+00:00Added an answer on June 10, 2026 at 7:03 pm

    Did I understand correctly the reason for alerting 1

    Yes

    “But this does not mean that the value of a variable assignment does not replace the function”
    What does the above line means ? (the misunderstood part)

    It just means that although a function with name a is already defined, a = 10 is still going to be executed, i.e. after that line a does not refer to a function anymore but to 10.

    I assume they wanted to relax the previous statement a bit and avoid that people incorrectly think that because the function declaration is executed first, the assignment would not take place anymore.


    Function and variable declarations are hoisted to the top of the scope. So the code is equivalent to:

    1:   var a = 1;
    2:   function b () {
    3:       function a() {}
    4:       a = 10;
    5:       return;
    6:   }
    7:   b();
    8:   alert(a);
    

    function a() {...} creates a symbol (variable) a in the local scope and its value is the very same function. The next line, a = 10;, then assigns a new value to that symbol, namely a number.

    var a = 1;
    function b () {
         function a() {} // creates a new local symbol `a`, shadowing the outer `a`
         // until here, `a` refers to the function created 
         // created by the above declaration
         a = 10; // now a new value is assigned to the local symbol/variable `a`
         // from here on, `a` is `10`, not a function
         return;
    }
    b();
    alert(a);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After reading this article . I have some questions about NTLM Authentication. When I
Reading this article http://support.microsoft.com/kb/813878 I have a question: Where can I get ipseccmd.exe for
I have been reading this similar SO question but some of the approaches suggested
After reading this article I don't have a clear answer: http://palizine.plynt.com/issues/2010Oct/bypass-xss-filters/ Will browsers interpret
i have been reading this interesting article which is increasing my every growing confusion
I was just reading this article and it mentions that some organization had an
When looking at questions and answers on this site and reading some of the
I have a question about how to use Dispose() and destructors. Reading some articles
I'm asking the question after reading this article http://stevehanov.ca/blog/index.php?id=95 Also isn't it a penalty
I have been reading some articles on memory leaks in Android and watched this

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.