How to test if a variable is defined in JavaScript

How to test if a variable is defined in JavaScript

if ( 'null' !== someVar && ( typeof someVar === 'undefined') ) {
  // Your variable is undefined
}
if( !x ){
   //undefined
}

Second code can be incorrect if x is being set from a function call. like x = A(); if A doesnt return anything, it will return “undefined” by default. Doing a !x would be true which would be logically correct. However, if A() returns 0 then !x should be false as x=0. However in JS, !0 is also true.