JavaScript Null Checking, Undefined and ! Unary Operator
Google searches of "JavaScript null check" and "How to check for null in JavaScript" were returning results that left something to be desired in my opinion, so I compiled this list.
See the code live here: JsFiddle: http://jsfiddle.net/aaronhoffman/DdRHB/5/
Code also available here:
https://github.com/aaronhoffman/utils/blob/master/JavaScript/NullChecks.js
Comparison Chart:
Hope this helps,
Aaron
p.s. I used a great tool Regex Pixie http://www.regexpixie.com/ by StoneFinch http://stonefinch.com/ to generate most of the code in this example (disclaimer, I currently work for them, however I would never promote a tool I don't use myself.)
See the code live here: JsFiddle: http://jsfiddle.net/aaronhoffman/DdRHB/5/
Code also available here:
https://github.com/aaronhoffman/utils/blob/master/JavaScript/NullChecks.js
Comparison Chart:
Hope this helps,
Aaron
p.s. I used a great tool Regex Pixie http://www.regexpixie.com/ by StoneFinch http://stonefinch.com/ to generate most of the code in this example (disclaimer, I currently work for them, however I would never promote a tool I don't use myself.)
Comments