How to check if a JavaScript variable is NOT undefined? [duplicate] October 7, 2022 by Tarik var lastname = "Hi"; if(typeof lastname !== "undefined") { alert("Hi. Variable is defined."); }