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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:54:18+00:00 2026-05-14T15:54:18+00:00

In Javascript, when is a new scope created? The 2 situations I know of

  • 0

In Javascript, when is a new scope created? The 2 situations I know of are:

  1. with a new function (update on 2012/09, I think it needs to be a function invocation, not just a function definition)
  2. in a “with” statement

as a note, any new block (in if-then-else, loops, or just beginning a block for no other reason) won’t create a new scope.

Is there a third situation where a new scope is created besides the two situations above? 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-14T15:54:18+00:00Added an answer on May 14, 2026 at 3:54 pm

    Yes, there is a third case where the scope chain is augmented (besides the let mozilla-extension that Shog9 mentions), when a catch block is evaluated:

    The production Catch : catch
    (Identifier ) Block is evaluated as
    follows:

    1. Let C be the parameter that has been passed to this production.

    2. Create a new object as if by the expression new Object().

    3. Create a property in the object Result(2). The property’s name is
      Identifier, valueisC. value, and
      attributes are { DontDelete }.

    4. Add Result(2) to the front of the scope chain.

    5. Evaluate Block.

    6. Remove Result(2) from the front of the scope chain.

    7. Return Result(5).

    So basically, a new object is created, with a property named like the Identifier passed to catch, this new object is added to the scope chain, so we are able to use that identifier within the catch block.

    try {
      throw "error";
    } catch (identifier) {
      // `identifier` accessible here..
    }
    

    But keep in mind that it only augments the current scope temporarily, to introduce the catch Identifier, any variable declared inside will be simply hoisted to the top of it enclosing function.

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

Sidebar

Related Questions

I noticed that JavaScript's new Date() function is very smart in accepting dates in
I'm using Nodejs and Socket.io. When the client connects, new JavaScript objects are created.
Very new to javascript and html-type stuff. I wanted to just make a quick
im new at javascript and i can get this slider to work but not
If the with statement in Javascript creates a new scope, shouldn't clicking on the
I am relatively new to programming with PHP. I have created a simple Javascript
Given the following snippet of javascript in a scope: var x = 10; function
I am new to JavaScript and I am having trouble understanding the scope of
I'm new to CPP, and I want to know how to run a function
Currently we're using javascript new RegExp('#[^,#=!\s][^,#=!\s]*') (see [1]) and it mostly works, except that

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.