Hello, I have been strugling with some variables that are the type of undefined. I’ve looked on internet but I found nothing on how to determine if it’s “undefined” like this :
if (typeof tmp == "undefined") {
    tmp = [0, 0];
    console.log("tmp is undefined");
}
Has anyone as a solution to counter this?
             
            
              
              
              1 Like
            
            
           
          
            
            
              you can just do
var tmp;
console.log(tmp === undefined);//true
tmp = 'hmm';
console.log(tmp === undefined);//false
             
            
              
              
              2 Likes
            
            
           
          
            
            
              Both undefined & null got no members in them: 
Therefore, we can’t do anything w/ them but check for their presence. 
But b/c both of them are considered “falsy” values we can greatly simplify their check w/ just: 
if (!tmp) tmp = [0, 0]; or tmp = tmp || [0, 0];. 
Rather than if (tmp == undefined) tmp = [0, 0];. 
             
            
              
              
              1 Like
            
            
           
          
            
            
              Thanks a lot, it worked as expected 