Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #26941

Re: What's wrong with this code?

From Joao Rodrigues <groups_jr-1@yahoo.com.br>
Newsgroups comp.lang.javascript
Subject Re: What's wrong with this code?
Date 2015-02-26 14:09 -0300
Organization Aioe.org NNTP Server
Message-ID <mcnk0c$i59$1@speranza.aioe.org> (permalink)
References <b2751271-cbda-4bcd-9217-a37eb3fa58b0@googlegroups.com>

Show all headers | View raw


On 02/26/2015 06:18 AM, denissavenok@gmail.com wrote:
> The function doesn't work as expected. Why?
>
> var isUndefinedOrNull = function(obj) {
>          return /^(?:undefined|null)$/.test(typeof obj);
> };
>

As (x === undefined || x === null) is the same as (x == null), we may 
rewrite the function to:

var isUndefinedOrNull = function (obj) {
   return (obj == null);
};

See:

<http://davidwalsh.name/fixing-coercion>

and

<http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/>


-- 
Joao Rodrigues

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

What's wrong with this code? denissavenok@gmail.com - 2015-02-26 01:18 -0800
  Re: What's wrong with this code? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-26 12:17 +0100
  Re: What's wrong with this code? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-26 14:25 +0000
    Re: What's wrong with this code? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-26 16:04 +0100
      Re: What's wrong with this code? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-02-26 15:37 +0000
        Re: What's wrong with this code? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-02-26 17:09 +0100
  Re: What's wrong with this code? Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-02-26 14:09 -0300

csiph-web