Checking for null in a script

Post your questions and help other users.

Moderator: Martin

Post Reply
manuel
Posts: 27
Joined: 05 Jul 2013 20:54

Checking for null in a script

Post by manuel » 30 Jul 2013 12:43

What is the right syntax to check for a null value?

Can I just use the following?

Code: Select all

if ( a != null) {
...
}

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Checking for null in a script

Post by Martin » 30 Jul 2013 16:53

Yes, this code should work:

Code: Select all

a=null;
if (a==null) {
  log("null");
}
else {
  log("not null");
}
or

Code: Select all

a=null;
if (a!=null) {
  log("not null");
}
else {
  log("null");
}

Post Reply