How to check if a variable is NOT undefined

Checking undefined is not work when we go normal if statement, As like below

var id=$('#txt').val();

if(id != 'undefined')
{
// Our Code
}

"id" is var type, i.e mean unknown type, such as whether "id" is string, numeric, or even undefined.  
if "txt" is not defined in the page, then its value is  undefined is a one of type, so we shall check the type of operand with value.

By using "typeof" operator we resolve above issue. The "typeof" operator in JavaScript/Jquery allows you to probe the data type of its operand.

var item = 10;
alert(typeof item); This returns the type of item not value.


if(typeof id != 'undefined')
{
// Our Code


I hope this will help you to resolve the problem.