Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-18 Thread J.R.
On Monday, 18 April 2011 18:22:53 UTC-3, Angus Croll wrote: > > Hey Jao > > I'm not advocating for or against coercion I'm just pointing out Douglas > made a mistake on that page > > He strongly implied that if(foo) and if(foo != 0) are the same. But they > are not the same and he completely avoi

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-18 Thread Angus Croll
Hey Jao I'm not advocating for or against coercion I'm just pointing out Douglas made a mistake on that page He strongly implied that if(foo) and if(foo != 0) are the same. But they are not the same and he completely avoided a discussion of why they are not the same. His words: f you want the

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-18 Thread J.R.
On Monday, 18 April 2011 17:01:04 UTC-3, Angus Croll wrote: > > Hey JR > > He didn't say If (foo) { } is the same as if (foo !== 'undefined') { } > He said If (foo) { } is the same as if (foo != 0) { } > > ( page 121 of The Good Parts) > > Hi Angus, In that (good) part of the book, Douglas Crockfo

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-18 Thread Angus Croll
Hey JR He didn't say If (foo) { } is the same as if (foo !== 'undefined') { } He said If (foo) { } is the same as if (foo != 0) { } ( page 121 of The Good Parts) The former case uses toBoolean the latter uses toPrimitive therefore: var foo = [0]; console.log(foo ? true : false) //true consol

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-18 Thread J.R.
On Monday, 18 April 2011 14:57:01 UTC-3, Angus Croll wrote: > > Just for the record my original post was not about == vs === > > It was about Crockford's false claim that (!x) is the same as (x != 0) > > fails for cases such as x = "0" and x = [0] > > This is because former does ToBoolean coercio

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-18 Thread Tim Down
On 18 April 2011 07:15, Olov Lassus wrote: > On Apr 18, 1:18 am, Tim Down wrote: >> In a typeof comparison, there's no technical reason to favour either >> operator over the other, since they will behave identically. Saving a >> keystroke and a character in the script delivered to the client is a

[JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-17 Thread Olov Lassus
On Apr 18, 1:18 am, Tim Down wrote: > In a typeof comparison, there's no technical reason to favour either > operator over the other, since they will behave identically. Saving a > keystroke and a character in the script delivered to the client is a > tiny but tangible benefit of using ==. The ben

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-17 Thread Tim Down
On 17 April 2011 22:44, Olov Lassus wrote: > On Apr 15, 11:50 am, Diego Perini wrote: >> In this case both sides of the conditional expression contains strings >> and no type conversion is necessary so "!=" is preferred. >> >> Strict comparison "!==" could be used without any problem, but there >

[JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-17 Thread Olov Lassus
On Apr 15, 11:50 am, Diego Perini wrote: > In this case both sides of the conditional expression contains strings > and no type conversion is necessary so "!=" is preferred. > > Strict comparison "!==" could be used without any problem, but there > is no real reason to use it in this case once we

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-15 Thread J.R.
On Friday, 15 April 2011 06:50:45 UTC-3, Diego Perini wrote: > > On Fri, Apr 15, 2011 at 5:08 AM, J.R. wrote: > As the typeof operator (ECMA-262 3rd ed, 11.4.3) returns a string, then it > > is safe, in this case, to use either the != or !== equality operators. > > In this case both sides of the

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-15 Thread Diego Perini
On Fri, Apr 15, 2011 at 5:08 AM, J.R. wrote: > On Wednesday, 13 April 2011 19:37:59 UTC-3, Asen Bozhilov wrote: >> >> J.R.: >> >> > Instead of: >> >   if (window.ActiveXObject) { >> > >> > We should use: >> >   if (typeof window.ActiveXObject !== "undefined") { >> >> I would not use both approache

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-14 Thread J.R.
On Wednesday, 13 April 2011 19:37:59 UTC-3, Asen Bozhilov wrote: > > J.R.: > > > Instead of: > > if (window.ActiveXObject) { > > > > We should use: > > if (typeof window.ActiveXObject !== "undefined") { > > I would not use both approaches. I would use: > > if (typeof ActiveXObject != 'undefined

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-13 Thread Asen Bozhilov
J.R.: > Instead of: > if (window.ActiveXObject) { > > We should use: > if (typeof window.ActiveXObject !== "undefined") { I would not use both approaches. I would use: if (typeof ActiveXObject != 'undefined') { //... } Or as Diego proposed: if ('ActiveXObject' in this) { //... } When

Re: [JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-13 Thread Diego Perini
On Wed, Apr 13, 2011 at 11:55 PM, J.R. wrote: > On Tuesday, 12 April 2011 02:12:31 UTC-3, Angus Croll wrote: >> >> Douglas Crockford is a JavaScript hero and a great communicator. I learned >> a lot from his writings and his excellent video series >> (http://net.tutsplus.com/tutorials/javascript-a

[JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-12 Thread RobG
On Apr 12, 3:12 pm, Angus Croll wrote: > Douglas Crockford is a JavaScript hero and a great communicator. I learned a > lot from his writings and his excellent video series > (http://net.tutsplus.com/tutorials/javascript-ajax/crockford-on-javasc...) > > We all make mistakes and I'm sure I make m

[JSMentors] Re: Bad Coercion Advice from a Guru (or why you should question everything)

2011-04-11 Thread Angus Croll
Whoops. Proof that everyone makes mistakes - typo in my second example! I meant to write: console.log(foo != 0); //false On Apr 11, 10:12 pm, Angus Croll wrote: > Douglas Crockford is a JavaScript hero and a great communicator. I learned a > lot from his writings and his excellent video series >