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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:14:31+00:00 2026-05-10T18:14:31+00:00

Today I had a discussion with a colleague about nested functions in Javascript: function

  • 0

Today I had a discussion with a colleague about nested functions in Javascript:

function a() {    function b() {       alert('boo')    }    var c = 'Bound to local call object.'    d = 'Bound to global object.' } 

In this example, trials point out that b is not reachable outside the body of a, much like c is. However, d is – after executing a(). Looking for the exact definition of this behaviour in the ECMAScript v.3 standard , I didn’t find the exact wording I was looking for; what Sec.13 p.71 does not say, is which object the function object created by the function declaration statement is to be bound to. Am I missing something?

  • 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. 2026-05-10T18:14:32+00:00Added an answer on May 10, 2026 at 6:14 pm

    This is static scoping. Statements within a function are scoped within that function.

    Javascript has a quirky behavior, however, which is that without the var keyword, you’ve implied a global variable. That’s what you’re seeing in your test. Your "d" variable is available because it is an implied global, despite being written within the body of a function.

    Also, to answer the second part of your question: A function exists in whatever scope it is declared, just like a variable.

    Sidenote: You probably don’t want global variables, especially not implied ones. It’s recommended that you always use the var keyword, to prevent confusion and to keep everything clean.

    Sidenote: The ECMA Standard isn’t probably the most helpful place to find answers about Javascript, although it certainly isn’t a bad resource. Remember that javascript in your browser is just an implementation of that standard, so the standards document will be giving you the rules that were (mostly) followed by the implementors when the javascript engine was being built. It can’t offer specific information about the implementations you care about, namely the major browsers. There are a couple of books in particular which will give you very direct information about how the javascript implementations in the major browsers behave. To illustrate the difference, I’ll include excerpts below from both the ECMAScript specification, and a book on Javascript. I think you’ll agree that the book gives a more direct answer.

    Here’s from the ECMAScript Language Specification:

    10.2 Entering An Execution Context

    Every function and constructor call enters a new execution context, even if a function is calling itself recursively. Every return exits an execution context. A thrown exception, if not caught, may also exit one or more execution contexts.

    When control enters an execution context, the scope chain is created and initialised, variable instantiation is performed, and the this value is determined.

    The initialisation of the scope chain, variable instantiation, and the determination of the this value depend on the type of code being entered.

    Here’s from O’Reilly’s Javascript: The Definitive Guide (5th Edition):

    8.8.1 Lexical Scoping

    Functions in JavaScript are lexically rather than dynamically scoped. This means that they run in the scope in which they are defined, not the scope from which they are executed. When a function is defined, the current scope chain is saved and becomes part of the internal state of the function. …

    Highly recommended for covering these kinds of questions is Douglas Crockford’s book:

    JavaScript, The Good Parts http://oreilly.com/catalog/covers/9780596517748_cat.gif

    Javascript, The Good Parts, also from O’Reilly.

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

Sidebar

Ask A Question

Stats

  • Questions 120k
  • Answers 120k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Take a look at jQuery live. This will let you… May 12, 2026 at 12:08 am
  • Editorial Team
    Editorial Team added an answer Have you looked at the big one, Dundas Chart? It… May 12, 2026 at 12:08 am
  • Editorial Team
    Editorial Team added an answer That's very strange. All I can think is that you… May 12, 2026 at 12:08 am

Related Questions

I had a discussion with a developer earlier today re identifying TCP packets going
Long version... A co-worker asserted today after seeing my use of while (1) in
I'm writing this question with reference to this one which I wrote yesterday. After
(Not to be confused with Xunit , a popular .Net unit testing library.) Today

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.