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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:00:14+00:00 2026-06-17T09:00:14+00:00

I was wondering if I can add to Javascript’s document object. Like: var document

  • 0

I was wondering if I can add to Javascript’s document object. Like:

var document = {
    name: "My Name"   
}
  • Is that legal in JavaScript?
  • If it is, is it considered “good practice”, or should I avoid it?
  • If I define it as a variable, is it then considered as a unique object, and not a JS DOM object?

I am plenty new to JavaScript and any help would be much appreciated.

Edit:

After some conversation in the comments and a little more thought on it, I really want to know if I can manipulate the document variable and still use document for normal use.

  • 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-17T09:00:15+00:00Added an answer on June 17, 2026 at 9:00 am
    • Yes you can do that
    • No you shouldn’t do that

    document is just another property of the global / window object. If you declare it as formal parameter or variable within a scope, the lookup process will match that name first in that scope you declared it, so it kinda overlaps it.

    Regardless, you don’t want to do it, why would you ? Its so confusing for you and anybody else who is looking at your code. Its very bad practice.

    Actually, that is the reason why most “advanced” javascript snippets / libraries begin with a closured function scope like

    (function( window, document, undefined ) {
        // window will always reference the "window" object that got originally passed in
        // document will always reference the "document" object that got originally passed in
        // undefined will always reference the "undefined value" that got originally passed in
    }( window, window.document ));
    

    ..just to avoid, the such called asshole effect. If such a closure is openend at the very top of a file, it makes sure that you reference the original objects within, just in case some genius had the great idea to overwrite/overlap them.

    Conclusion: You are of course free to choose the name of your
    variables at will, but you really shouldn’t use the name of such
    prominent names like window, document, undefined et cetera for
    obvious reasons.

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

Sidebar

Related Questions

I was wondering how I can add \label into bibtex so that when I
i was wondering if i can add/append a javascript to an iframe which is
I was wondering how I can add a new directory in my perl settings
I was wondering, I am aware you can use assert to add facts or
I have a website that stores quotes and users can add some quotes to
Can I add an object of Elements inside another DOM element using grab or
I have written a little JQuery / Javascript add on for our form, that
I am wondering about javascript prototype. I know that prototyping enables the user to
I'm wondering how I can add a select list to a from. Here's my
I'm pretty new to javascript and am wondering about quoting the keys in object

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.