STOP Declaring IDs!?! JavaScript Global Variables Best Practices



🦸 Become A VS Code SuperHero Today: https://vsCodeHero.com
πŸ§‘πŸΎβ€πŸ€β€πŸ§‘πŸ½ Join my Discord developer community: https://discord.gg/A9CnsVzzkZ

Did you know that you don’t have to use getElementById() or querySelector() to access a DOM element that has an HTML ID?
HTML element IDs are accessible as global variables on the window object.
So, should we stop using `getElementById()` and `querySelector()`?
NO
Even though this does seem to be a convenient way to write a little less code, it should not be used.
It’s always good practice to declare your variables.
_____________________________________
πŸ€– Get FREE AI-powered code completions from Kite: https://www.kite.com/get-kite/?utm_medium=referral&utm_source=youtube&utm_campaign=codestackr&utm_content=description-only
πŸ“š FREE 7-Day trial at Treehouse: https://treehouse.7eer.net/codeSTACKr
_____________________________________

πŸ› οΈ Tools I use:
🟠 codeSTACKr Theme: https://marketplace.visualstudio.com/items?itemName=codestackr.codestackr-theme
🟠 STACKr Code Font (Exclusive to my VS Code Course – https://vsCodeHero.com)
🟠 SuperHero Extension Pack: https://marketplace.visualstudio.com/items?itemName=codeSTACKr.superhero-extensions
_____________________________________

πŸ’– Show support!
PayPal: https://paypal.me/codeSTACKr
_____________________________________

πŸ‘€ Watch Next:
Playlist: Web Development For Beginners – https://www.youtube.com/watch?v=Ez4yHS2dsN8&list=PLkwxH9e_vrAJ0WbEsFA9W3I1W-g_BTsbt
_____________________________________

🌐 Connect With Me:
Website: https://www.codestackr.com
Twitter: https://twitter.com/codeSTACKr
Instagram: https://instagram.com/codeSTACKr
Facebook: https://facebook.com/codeSTACKr
_____________________________________

** Affiliate Disclaimer: Some of the above links may be affiliate links, which may generate me a sales commission at no additional cost to you.

#codeSTACKr #JavaScript #learntocode

source

You May Also Like