• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Checking for Null value

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my procject we are using Internet Explorer 6.

I have added a new code-

------------------------
if (document != null && document.title != null && document.title == "Entry Event Tracking"
&& aListOfAppLockInfo != null && aListOfAppLockInfo[aListOfAppLockInfo.length -1] != null &&
aListOfAppLockInfo[aListOfAppLockInfo.length -1].owner_type != null && aListOfAppLockInfo[aListOfAppLockInfo.length -1].owner_type != "SESSION"){
return true;
}
------------------------

aListOfAppLockInfo is an array. It hold's different object's. Each object's has their own properties.
So i need to check for property 'SESSION'.

Can anybody let me know, my above code is correct and it will never fail, even if there is any null value?
Any suggestions also to improve this code.

Thanks in Advance.
 
Ranch Hand
Posts: 326
Android Mac OS X Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to put up a cross matrix and see if you have any holes in it and with all this in one line you might miss something.

I would suggest that you break it down to at least two different ifs, one for all terminating controls (all items that may not be null) and one for the check if value present.
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ove for your reply.

As you have suggested to break it into one for checking null and other for checking value's.

Is this only for testing purpose you have asked me or to modify the original code also?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try debugging it as mentioned



See which one fails. When you find it, alert the values and see what is wrong.

Eric
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Eric for your reply.

Well i tested through alert's, it's all working as expected.

Now the question i do have which piece of code should i use?

----------------------------
if (document != null && document.title != null && document.title == "Entry Event Tracking"
&& aListOfAppLockInfo != null && aListOfAppLockInfo[aListOfAppLockInfo.length -1] != null &&
aListOfAppLockInfo[aListOfAppLockInfo.length -1].owner_type != null && aListOfAppLockInfo[aListOfAppLockInfo.length -1].owner_type != "SESSION"){
return true;
}
-----------------------------

OR

this cross matrix form

----------------------------
if (document != null && document.title != null
&& aListOfAppLockInfo != null && aListOfAppLockInfo[aListOfAppLockInfo.length -1] != null &&
aListOfAppLockInfo[aListOfAppLockInfo.length -1].owner_type != null ){
if (document.title == "Entry Event Tracking" && aListOfAppLockInfo[aListOfAppLockInfo.length -1].owner_type != "SESSION"){
return true;
}
}
-------------------------------

which one is less error prone?
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They do the same thing. Do what you like.

Eric
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eric.
 
The glass is neither half full or half empty. It is too big. But this tiny ad is just right:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic