Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.javascript Subject: Re: What's wrong with this code? Date: Thu, 26 Feb 2015 14:25:22 +0000 Organization: A noiseless patient Spider Lines: 16 Message-ID: <8761aopx65.fsf@bsb.me.uk> References: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: mx02.eternal-september.org; posting-host="017616aa25f81ec581c44d76d61ba2f3"; logging-data="15494"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19vq0pp54yCp/Ns1i5fWlsW4wuKoB5HtAg=" Cancel-Lock: sha1:mBv9CrePAJeBbDF+a8iNmXaP5+E= sha1:Or/Jv4XheFafI+3Qs+s+79vaims= X-BSB-Auth: 1.6a3d497bdcc4ffbcb4ea.20150226142522GMT.8761aopx65.fsf@bsb.me.uk Xref: csiph.com comp.lang.javascript:26937 denissavenok@gmail.com writes: > The function doesn't work as expected. Why? > > var isUndefinedOrNull = function(obj) { > return /^(?:undefined|null)$/.test(typeof obj); > }; If the type of obj is Null, typeof is defined to yield 'object'. You might (in some very odd implementation) get 'null' from typeof, but that's only because the result is up to the implementation in some very specific cases. -- Ben.