If you need to use document.getElementById("my-input")
for something else, put it in a separate variable. If you will only ever need the .value
, your first option is fine. There’s no point in separating it out if you’re not going to utilise that separation.
1
solved What is the difference when using Javascript’s .value?