How to determine if variable is 'undefined' or 'null'?

How do I determine if variable is undefined or null? My code is as follows:

var EmpName = $(div#esd-names div#name).attr('class');
 if(EmpName == 'undefined')
{
   
//DO SOMETHING 
};
 
<div id=esd-names>   <div id=name></div> </div> 

But if I do this, the JavaScript interpreter halts execution.

Text Copied From stackoverflow.com
on : Thu, Apr 15, 2010 Views : 1799107

Accepted Answer

You can use the qualities of the abstract equality operator to do this:

if (variable == null)
{

  
// your code here. 

Because null == undefined is true, the above code will catch both null and undefined.

Text Copied From stackoverflow.com
on : Thu, Apr 15, 2010

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp