Which method of checking if a variable has been initialized is better/correct?
(Assuming the variable could hold anything (string, int, object, function, etc.))

if (elem) { // or !elem

or

if (typeof elem !== 'undefined') {

or

if (elem != null) {

31 Answers
31

Leave a Reply

Your email address will not be published. Required fields are marked *