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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:06:00+00:00 2026-06-11T06:06:00+00:00

(Maybe) I just solved a my problem ( How to update front-end content after

  • 0

(Maybe) I just solved a my problem (How to update front-end content after that a form is successfully submitted from a dialog window?) by “storing” / “saving” a variable in the JavaScript window object. However, since I am newbie in JavaScript matters, I have some doubts if storing / saving a variable in the JavaScript window object is a “common” / “proper” way to use that object. Is it?

For example, using the following code

$('.trigger').click(function() {
  window.trigger_link = this;
});

is advisable?

  • 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-11T06:06:01+00:00Added an answer on June 11, 2026 at 6:06 am

    In JavaScript, any global variable is actually a property of the window object. Using one is equivalent to (and interchangeable with) using the other.

    Using global variables is certainly “common,” so the question is whether or not it’s “proper.” Generally, global variables are discouraged, because they can be accessed from ANY function and you risk having multiple functions trying to read from and write to the same variables. (This is true with any programming language in any environment, not just JavaScript.)


    Solve this problem by creating a namespace unique to your application. The easiest approach is to create a global object with a unique name, with your variables as properties of that object:

    window.MyLib = {}; // global Object container; don't use var
    MyLib.value = 1;
    MyLib.increment = function() { MyLib.value++; }
    MyLib.show = function() { alert(MyLib.value); }
    
    MyLib.value=6;
    MyLib.increment();
    MyLib.show(); // alerts 7
    

    Another approach is to use .data() to attach variables to a relevant DOM element. This is not practical in all cases, but it’s a good way to get variables that can be accessed globally without leaving them in the global namespace.

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

Sidebar

Related Questions

Not that it matters strictly, and maybe I just don't yet fully understand how
Maybe it's just the fact that I've been using http://nodejs.org/ lately, but the lack
EDIT2: [SOLVED] The create method in the controller file does not end until after
Maybe I just can't figure out the right keywords to get an answer out
Maybe I just haven't figured out the InfoPath paradigm yet, but any links, or
Maybe I just don't know enough about structs and have been using them blindly
I'am new to extJS and maybe I just don't know the correct strategy, so
Doesn't seem to work for me, maybe I just doing it wrong
I'm interested in texture streaming in DirectX but google seems unhelpful. Maybe I just
Maybe I am just over thinking this and need to write some more prototype

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.