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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:13:51+00:00 2026-05-19T22:13:51+00:00

For example var w = document.getElementById; var b = w(‘header’); var c = w(‘footer’);

  • 0

For example

var w = document.getElementById;
var b = w('header');
var c = w('footer');
var d = w('body');

Edit: Semicolons are another one of those big arguments. I thought I would edit the question for fun.

Edit: Responses to Andrey‘s comments found on his answer.

“How does copying reference make it more effective with JS compilers?”
Response: JS compilers are to shorten and/or obfuscate code. If there were 40 calls to document.getElementById(..), it would be much more compact if they called getById(..) which would be renamed to something like O(..).

“Also, when you handle html element events, you usually specify a js method, and inside the method you put the logic, not directly in the html event handlers – that is not required but a good practice”
Response: I know. But we have many many web systems and they rarely follow good practice completely.

“Also, using built in methods directly makes the code way more readable”
Response: Given these two examples, I think the latter is more readable

document.getElementById('total').value = document.getElementById('subtotal').value + document.getElementById('salestax').value - document.getElementById('discount').value
document.getElementById('yousaved').value = document.getElementById('discount').value / (document.getElementById('subtotal').value + document.getElementById('salestax').value)

or

var byId = document.getElementById
byId('total').value = byId('subtotal').value + byId('salestax').value - byId('discount').value
byId('yousaved').value = byId('discount').value / (byId('subtotal').value + byId('salestax').value)
  • 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-19T22:13:52+00:00Added an answer on May 19, 2026 at 10:13 pm

    Did you mean

    var w = document.getElementById
    

    ?

    Thsi link explains in detail why you shouldn’t do that: JavaScript function aliasing doesn't seem to work

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

Sidebar

Related Questions

For example if I assign var n = document.getElementById('A').childNodes.length; And then later append a
for example this code var html = <p>This text is <a href=#> good</a></p>; var
Say for example I have the following string: var testString = Hello, world; And
For some reason I'm not getting this. (Example model below) If I write: var
How may I check if 2 Dom element are same. Form example var element1
So for example I have a structure like this: Javascript function toggle(id){ var element
<div id=mydiv> <p> <b><a href=mypage.html>This is an example<a>.</b> <br> This is another example. </p>
Example: You have a shortcut s to SomeProgram in the current directory. In cmd.exe
Example I have Person , SpecialPerson , and User . Person and SpecialPerson are
Example: select ename from emp where hiredate = todate('01/05/81','dd/mm/yy') and select ename from emp

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.