Is there a reason as to why we declare the variables as constant while selecting elements from the DOM? I see a lot of devlopers and tutorials use
const form = document.querySelector('form');
Is there a reason as to why we declare the variables as constant while selecting elements from the DOM? I see a lot of devlopers and tutorials use
const form = document.querySelector('form');
You want to store the result so you do not have to query it again. And it is also best practice to use const
as often as you can so you cannot accidentally reasign it. In case you DO need to reasign it, it is preferable to use let
.