I am trying to catch the element when the value of the input is null but the if statement isn't working.
for (let i = 0; i<esquema.length; i++){
if (esquema[i].checked){
console.log(esquema[i].value);
if (esquema[i].value == null){
console.log ("Actually null");
}
}
}
The output should be
null
Actually null
But instead of that i am getting
null
undefined
Can someone help me with this?
The
value
of an HTMLElement is eitherundefined
if it is not an<input>
(<button>
, ...) element, or it is a string. As it is notundefined
(as it logsnull
, andnull == undefined
would be true), it has to be"null"
which would lognull
but would not be equal tonull
.Most consoles do print
null
and"null"
differently though, log both and compare the results to see the difference.