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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:31:37+00:00 2026-05-15T09:31:37+00:00

I prefer to declare one Javascript file for my all website. I am trying

  • 0

I prefer to declare one Javascript file for my all website. I am trying to decrease the usage of global variables. My examples at the below, in both case each object has a myName field.

  1. I would like to know when they are initialized?
  2. And In terms of memory and efficiency which one is more effective?
  3. For variable a, is declaring a.myName the same as global “var myName = Rebecca” ?
var a = {
   myName : 'Rebecca' ,

   sayHello : function() {
      console.log(this.myName);
   }
};

var b = {
   myName : function() {
      return 'Rebecca';
   },

   sayHello : function() {
      console.log(this.myName());
   }
};

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-15T09:31:38+00:00Added an answer on May 15, 2026 at 9:31 am
    1. I believe these will be initialized identically (i.e. when the code is reached). What’s different is what’s happening when they are initialized and where the load is placed when their data is actually required.

    2. To me, it would depend a lot on what you were expecting to have in myName. If it were just a string, I’d avoid the function and go with choice a. On the other hand, if there were a great deal of logic involved and that logic might not need to be invoked (for example, if it only gets executed when a user clicks on a button or the application reaches a certain state), I’d go with choice b. As I understand it, the function does consume memory and won’t get garbage collected (which is a minus), but it also won’t consume CPU resources until it’s actually needed (which can be a huge plus).

    3. I’m not sure I understand the question, but I’d say it’s not the same. If the only member of a is myName then the two are equivalent (both are occupying the global namespace. But if you have multiple properties, the savings become obvious. From your examples, I think it’s clear you understand this, so again I may not understand the question.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think you may find use of InternetGetLastResponseInfo which is… May 17, 2026 at 8:45 am
  • Editorial Team
    Editorial Team added an answer An import statement like import foo.bar.baz first imports foo, then… May 17, 2026 at 8:45 am
  • Editorial Team
    Editorial Team added an answer As I understand it, your issue is that you want… May 17, 2026 at 8:45 am

Trending Tags

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

Top Members

Related Questions

I prefer dark backgrounds for coding, and I've downloaded a jar file containing an
I prefer to use OOP in large scale projects like the one I'm working
Which one do you prefer to store text in your database? The original casing
I have a lengthy JavaScript file that passes JSLint except for used before it
I prefer to keep our SSIS packages in a solution on the server, not
Which way do you prefer to create your forms in MVC? <% Html.Form() {
I would much prefer to do this without catching an exception in LoadXml() and
I would prefer that a console app would default to multithreaded debug. warning level
I'd prefer my primary key field weren't visible in my edit page. If I
which method do you prefer for creating dynamic sql queries? formating or streaming? Is

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.