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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:28:11+00:00 2026-06-17T12:28:11+00:00

As I understand, when a variable is defined it gets attached to the ‘closest’

  • 0

As I understand, when a variable is defined it gets attached to the ‘closest’ local scope via this.

If no scope is set locally, the closest scope becomes window.

In strict mode, however, the local scope is set to undefined instead of window, as part of the ECMAscript 5 spec designed to limit misuse of the global scope.


Using an immediately invoked function expression pattern and strict mode for creating a jQuery plugin

;( function( $, window ){
   "use strict";
   var myScope = this;
   var myVar = 1;

   var myFunction = function(){
     console.log( myScope, myVar );
   } 

   $.myFunc = myFunction;

})( jQuery, window );

the local scope (context) isn’t created (via a function call) and thus set to undefined.

If the local scope is undefined and window.myVar is undefined, what is the scope of the variable myVar and how do you access it?

  • 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-17T12:28:12+00:00Added an answer on June 17, 2026 at 12:28 pm

    The this context variable has not anything to do with Scope, in terms of how ECMAscript implements Lexical scoping underneath.

    this will always reference the object of invocation, which can change during run-time, whereas the scope / context cannot get changed. You got two function invocations there, each of those has its own Execution Context and its own Activation Object respectively Lexical Environment Record, which are used by the implementation to store any local data like formal paramteres, variables and function declarations.


    What you are actually trying to achieve here, is to create a hash / namespace object which serves as container to hold data. Therefore, you shouldn’t assign this, but just create your own Object.

    var myScope = { };  // respectively Object.create( null );
    

    In strict mode, the implementation will just set this to undefined for any function which got invocated as is. That means, the value of this is decided of how a function gets called. In your case, its a self-executing function and hence, its this will always be undefined in strict mode and window (global) in non strict mode.

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

Sidebar

Related Questions

I understand this code calculates the sum of the args of a variable, however,
I've been have trouble understand this problem. If I change the variable name fifthViewController
In the following code, I am trying to understand how the variable whatami gets
I'm trying to understand how variable scope works when you bind an event. The
I don't quite understand static variables when defined in the implementation of an interface.
I understand the reference variable concept. It's an alias to the other variable. int
I am trying to understand how to use instance variable in Perl OO -
It is important to understand that it is the type of reference variable -
As I understand it you should always use a TextField for a variable length
I understand how exports works, but how can I create a variable in my

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.