STOP Declaring IDs!?! JavaScript Global Variables Best Practices

preview_player
Показать описание

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.
_____________________________________
_____________________________________

🛠️ Tools I use:
_____________________________________

💖 Show support!
_____________________________________

👀 Watch Next:
_____________________________________

🌐 Connect With Me:
_____________________________________

** 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
Рекомендации по теме
Комментарии
Автор

I've always used Classes for CSS and unique ID's for JavaScript. It makes my code cleaner and easier to maintain.

StarcoreLabs
Автор

When I first saw this I just imagined all the ways someone can mess up and confuse a codebase lol. Cool thing but I agree with you, people shouldn't be using it.

DThompsonDev
Автор

this feature is way more dangerous than helpful

beinyourguard
Автор

i didnt knew about this, thanks a lot

ziaahmad
Автор

PLEASE keep doing more update videos like this!

IkraamDev
Автор

I never knew this was a thing! Thanks for letting us know, it looked like a bad idea from the moment you started the demonstration. It also shows how much browsers are divided and how much consideration you have to put into JavaScript code without using something like Babel to run on most/all browsers.

joopie
Автор

Sir I don’t know english properly. Plz tell me what is the best practice ? Using getElementById() is the best practice ??

MohidulIslam-elfd
Автор

very informative. I was fasinated when you explain this stuff .Thank you so much for the explanation

thiyageshkanna
Автор

Loved the quality video. Short, informative and very much useful. Thanks codeSTACKr

JawadKhan-gcdu
Автор

Thank you for this info. Very informative incase we run into such use cases on open source libraries/code samples

uchechukwuprincenwulu
Автор

How did you make your vscode so smooth? Is it in the settings, or is it an extension? WOW

zerosandones
Автор

Thanks for this great direction and caution because not enough of it being conveyed.

GeorgeMonsour
Автор

This is an excellent tutorial. create a video on defining the DOM in depth and how to access and manipulate it in Javascript because all we know "DOM is the programmatic representation of a web page and what we see in the browser is the visual representation of the DOM" and there aren't in depth tutorials about explaining the DOM

salmanmurtaza
Автор

how is your editor so smooth does that has something to do with the extension or it's your monitor.

thatsalot
Автор

Love these vids, any new info is good info👍

aniruddharora
Автор

wow, long time confusion comes clear. i don't like to use getElementById but, now i understood the use of it. please make a video on clean code

suryam_
Автор

I made a video on my channel "Vuelancer" using this exact thing. It's a great feature!

vuelancer
Автор

what is ur vscode setting for this color and writing style

saunaknandi
Автор

Very well explained and informative video! Thank you man! =)

kaloianlawless
Автор

Which color theme do you used in vs code?

zubayerhossain
join shbcf.ru