for(const id of this.extraRooms)
{
let doesRoomExist = document.getElementById('newRoomAddress' + newRoomId);
//if(typeof(doesRoomExist) !== "null")
if(typeof(doesRoomExist) !== "undefined")
{
const newRoomLabel = document.getElementById('newRoomAddress' + newRoomId).value
{
Probably a simple fix but if doesRoomExist is NULL it is still going inside the if statement…
let doesRoomExist = document.getElementById('newRoomAddress' + newRoomId);
will show doesRoomExist as NULL when stepping through the code in VS code, but show as undefined if used in developer tools…why is it going inside the if?
any help please?
2
Answers
You should check the value of
doesRoomExist
directly not its type, you can either checkif (doesRoomExist !== null)
or just doingif (doesRoomExist)
will be enough;Just use
if (doesRoomExist) { /*...*/ }
.