Re: Cookie problem! Getting error when passing the expire date.
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Cookie problem! Getting error when passing the expire date.

From: Evertjan. <exjxw.hannivoort@interxnl.net>
Date: Sun Apr 30 2006 - 18:09:08 CEST

Lasse Reichstein Nielsen wrote on 30 apr 2006 in comp.lang.javascript:

>> x='0'
>> y=x|1
>> alert(y); // returns 1,
>> //"should" return 0, x being convertable to a number.
>
> And
> x='24'
> y = x|1;
> alert(y); // alerts 25

Wow! Yes.
 
> "Bitwise or" is not a logical guard in the way "logical or" is.
> This zero-problem would still be there for || though:
> Number("0") || 1
> yields 1 as well, since 0 converts to false.
>
> It really should be something like:
>
> function toNumberWithDefault(x,def) {
> var n = Number(x);
> return isNaN(n) ? def : n;
>}

alert(toNumberWithDefault('',7777)) // alerts 0

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Received on Mon May 1 05:27:57 2006