I was creating a validation form and by chance, I changed innerHTML of a div tag without declaring it at the top but that worked. I am not getting why that works without even declaring the error variable for div where I want to show the error
if(name == "") {
// why it works although I didn't
// declared nameError
nameError.innerHTML = "Name is required";
}
Following is the codepen example