var name = "someName";
if(name !=null) {
// do something
}
- I am right now using http://underscorejs.org/#isNull, how would i do
the same usingunderscore.js - Does it give any slight improvement in terms of performance for such
functions.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In underscore, you can use
and in plain Javascript, you should use
You should avoid the loose inequality operator
!=because it does type coercion andundefined != nullwill returnfalse.Using plain Javascript is slightly faster because it doesn’t have to invoke a function, but it will be imperceptible and it should hardly be a consideration.
I don’t have a strong preference either way as far as readability goes, but it seems a little excessive and verbose to call a library function for such a simple check.