Given an element with an id
or name
, browsers will create global JS variables containing references to them.
var numberInputBox = document.getElementById("numberInputBox");
would overwrite that variable. This would not affect the HTML element.
It could only cause problems if some other code attempted to use the global variable and expected it to have its original value (although in this case, the original value is the same as the new value).
In general, it is best to avoid creating global variables so that different scripts don't get in each other's way.
You can use an IIFE to scope them.
(function () {
var numberInputBox = document.getElementById("numberInputBox");
// Do other stuff with numberInputBox here because it is local to this function
}());