Didn't declared variable still not getting any error in JavaScript

25 views Asked by At

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

https://codepen.io/ihtisham-khan/pen/dyLVLeV

0

There are 0 answers