Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: What's wrong with this code? Date: Thu, 26 Feb 2015 16:04:21 +0100 Organization: PointedEars Software (PES) Lines: 34 Message-ID: <2083952.afr504CXY5@PointedEars.de> References: <8761aopx65.fsf@bsb.me.uk> Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1424963141 945 eJwFwQkRADAIAzBLPKUMORsH/iUsCaeyEwwiNvbJSMuKly5OHu2bML4wnQTmwulKWKp1VXwJhQ/a (26 Feb 2015 15:05:41 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 26 Feb 2015 15:05:41 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwFwYEBwCAIA7CXrEBx5yDY/09YEkaw0xn0UEi5PS1hJ/lwe3z0vS6ee8Zmf7Ef6kJc8FRZS2tlI2pI6x9UYhXC Cancel-Lock: sha1:APgx/Hrj0mX8+dZUrHTGgpWGeNU= X-NNTP-Posting-Host: eJwFwYEBwDAEBMCV8Hl0HCT2H6F3hKtPHKcfLndvJT5S+ilMr6a8ruKmJcZWZL2ixTE9mPgBHwERSw== Xref: csiph.com comp.lang.javascript:26938 Ben Bacarisse wrote: > 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. To be exact, a conforming implementation of ECMAScript could only provide "null" as the result of a “typeof” operation if the operand was a reference to a host object. An implementation that provided "null" for a primitive value or a reference to a native object would be non-conforming, which in *this* case means it is borken. -- PointedEars FAQ: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.