<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Note 2. ECMAScript. Equality operators.</title>
	<atom:link href="http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/feed/" rel="self" type="application/rss+xml" />
	<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/</link>
	<description>by Dmitry Soshnikov</description>
	<lastBuildDate>Sat, 04 Feb 2012 03:57:06 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Dmitry Soshnikov</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-11680</link>
		<dc:creator>Dmitry Soshnikov</dc:creator>
		<pubDate>Sun, 08 Jan 2012 10:22:15 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-11680</guid>
		<description>@&lt;b&gt;Steven&lt;/b&gt;, great! Glad to see this material is used in education.</description>
		<content:encoded><![CDATA[<p>@<b>Steven</b>, great! Glad to see this material is used in education.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steven</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-11676</link>
		<dc:creator>Steven</dc:creator>
		<pubDate>Sun, 08 Jan 2012 09:06:28 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-11676</guid>
		<description>Hey Dmitry, you&#039;re a genius man . nice work you got here.
I am an IT student and I need this for my class man.
Thanks for this great work. :)</description>
		<content:encoded><![CDATA[<p>Hey Dmitry, you&#8217;re a genius man . nice work you got here.<br />
I am an IT student and I need this for my class man.<br />
Thanks for this great work. <img src='http://dmitrysoshnikov.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry Soshnikov</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-11519</link>
		<dc:creator>Dmitry Soshnikov</dc:creator>
		<pubDate>Tue, 03 Jan 2012 17:53:56 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-11519</guid>
		<description>@&lt;b&gt;johnjbarton&lt;/b&gt;

&lt;blockquote&gt;There is no excuse for ==, it is just a waste of time.&lt;/blockquote&gt;

If to leave only one &lt;em&gt;strict&lt;/em&gt; operator, then to replace semantics of &lt;code&gt;==&lt;/code&gt; with the &lt;code&gt;===&lt;/code&gt;. But it&#039;s hard because of backward compatibilities -- we can&#039;t just leave only one equality operator now.

It&#039;s only possible with invention of a new language -- this is how CoffeeScript exactly does -- it compiles &lt;code&gt;==&lt;/code&gt; into the &lt;code&gt;===&lt;/code&gt;.

I agree that it&#039;s good to use only one style in order not to think about all the cases. But with e.g. the same &lt;code&gt;typeof&lt;/code&gt; I don&#039;t see any hazard using &lt;code&gt;==&lt;/code&gt; comparing with a string.

@&lt;b&gt;xx11&lt;/b&gt;

&lt;blockquote&gt;Interestingly these two lines are not equivalent. In the first case &lt;code&gt;a.valueOf()&lt;/code&gt; is called, in the second case - &lt;code&gt;a.toString()&lt;/code&gt;.&lt;/blockquote&gt;

Yes, it&#039;s true in your case since you compare different types on left and right hand sides.

But nevertheless, the end result after applying &lt;code&gt;+&lt;/code&gt; operator, is the string (according to &lt;a href=&quot;http://es5.github.com/#x11.6.1&quot; rel=&quot;nofollow&quot;&gt;11.6.1&lt;/a&gt;, step 7), so we compare strings having &lt;code&gt;&quot;&quot; + ...&lt;/code&gt; on both sides.

However, yes, it&#039;s a good note that &lt;code&gt;+&lt;/code&gt; calls &lt;code&gt;valueOf&lt;/code&gt; &lt;em&gt;first&lt;/em&gt; (and then, if it returns not a primitive, tries &lt;code&gt;toString&lt;/code&gt;) for the variable value; while &lt;code&gt;String&lt;/code&gt; applied as a function calls &lt;code&gt;toString&lt;/code&gt; directly. I&#039;ll add this note.</description>
		<content:encoded><![CDATA[<p>@<b>johnjbarton</b></p>
<blockquote><p>There is no excuse for ==, it is just a waste of time.</p></blockquote>
<p>If to leave only one <em>strict</em> operator, then to replace semantics of <code>==</code> with the <code>===</code>. But it&#8217;s hard because of backward compatibilities &#8212; we can&#8217;t just leave only one equality operator now.</p>
<p>It&#8217;s only possible with invention of a new language &#8212; this is how CoffeeScript exactly does &#8212; it compiles <code>==</code> into the <code>===</code>.</p>
<p>I agree that it&#8217;s good to use only one style in order not to think about all the cases. But with e.g. the same <code>typeof</code> I don&#8217;t see any hazard using <code>==</code> comparing with a string.</p>
<p>@<b>xx11</b></p>
<blockquote><p>Interestingly these two lines are not equivalent. In the first case <code>a.valueOf()</code> is called, in the second case &#8211; <code>a.toString()</code>.</p></blockquote>
<p>Yes, it&#8217;s true in your case since you compare different types on left and right hand sides.</p>
<p>But nevertheless, the end result after applying <code>+</code> operator, is the string (according to <a href="http://es5.github.com/#x11.6.1" rel="nofollow">11.6.1</a>, step 7), so we compare strings having <code>"" + ...</code> on both sides.</p>
<p>However, yes, it&#8217;s a good note that <code>+</code> calls <code>valueOf</code> <em>first</em> (and then, if it returns not a primitive, tries <code>toString</code>) for the variable value; while <code>String</code> applied as a function calls <code>toString</code> directly. I&#8217;ll add this note.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: xx11</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-11342</link>
		<dc:creator>xx11</dc:creator>
		<pubDate>Sat, 31 Dec 2011 07:52:14 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-11342</guid>
		<description>[js]
&quot;&quot; + a == &quot;&quot; + b // comparing strings

// the same, but more human-read versions

String(a) == String(b)
[/js]

Interestingly these two lines are not equivalent. In the first case &lt;code&gt;a.valueOf()&lt;/code&gt; is called, in the second case - &lt;code&gt;a.toString()&lt;/code&gt;.

[js]var obj1 = {
  toString: function() {return &quot;&quot;},
  valueOf: function() {return 1}
};

&quot;&quot;+obj1 == true; // true
String(obj1) == false; // also true[/js]</description>
		<content:encoded><![CDATA[<pre class="brush: jscript; title: ;">
&quot;&quot; + a == &quot;&quot; + b // comparing strings

// the same, but more human-read versions

String(a) == String(b)
</pre>
<p>Interestingly these two lines are not equivalent. In the first case <code>a.valueOf()</code> is called, in the second case &#8211; <code>a.toString()</code>.</p>
<pre class="brush: jscript; title: ;">var obj1 = {
  toString: function() {return &quot;&quot;},
  valueOf: function() {return 1}
};

&quot;&quot;+obj1 == true; // true
String(obj1) == false; // also true</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: johnjbarton</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-11072</link>
		<dc:creator>johnjbarton</dc:creator>
		<pubDate>Tue, 27 Dec 2011 00:12:36 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-11072</guid>
		<description>There is no excuse for ==, it is just a waste of time.</description>
		<content:encoded><![CDATA[<p>There is no excuse for ==, it is just a waste of time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-7297</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Fri, 16 Sep 2011 07:56:39 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-7297</guid>
		<description>@&lt;b&gt;John Merge&lt;/b&gt;

It&#039;s correct for Coffee&#039;s semantics. That is, there manual type casting is required. For JS semantics, I use myself often just &lt;code&gt;==&lt;/code&gt;, e.g. with &lt;code&gt;typeof&lt;/code&gt;.</description>
		<content:encoded><![CDATA[<p>@<b>John Merge</b></p>
<p>It&#8217;s correct for Coffee&#8217;s semantics. That is, there manual type casting is required. For JS semantics, I use myself often just <code>==</code>, e.g. with <code>typeof</code>.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Merge</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-7296</link>
		<dc:creator>John Merge</dc:creator>
		<pubDate>Fri, 16 Sep 2011 07:28:49 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-7296</guid>
		<description>Hmm, but... is it correct? I mean, I&#039;ve seen &#039; == &#039; to be used _intentionally_ by some developers.

Couldn&#039;t that conversion to lead to errors?</description>
		<content:encoded><![CDATA[<p>Hmm, but&#8230; is it correct? I mean, I&#8217;ve seen &#8216; == &#8216; to be used _intentionally_ by some developers.</p>
<p>Couldn&#8217;t that conversion to lead to errors?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-7274</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Mon, 12 Sep 2011 07:08:46 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-7274</guid>
		<description>@&lt;b&gt;John Merge&lt;/b&gt;

Right; that&#039;s why e.g. CoffeeScript translates &lt;code&gt;==&lt;/code&gt; directly into &lt;code&gt;===&lt;/code&gt;, avoiding non-strict equality at all.</description>
		<content:encoded><![CDATA[<p>@<b>John Merge</b></p>
<p>Right; that&#8217;s why e.g. CoffeeScript translates <code>==</code> directly into <code>===</code>, avoiding non-strict equality at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Merge</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-7273</link>
		<dc:creator>John Merge</dc:creator>
		<pubDate>Sun, 11 Sep 2011 20:42:03 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-7273</guid>
		<description>That&#039;s cool. I also completely agree with this sentence:
&quot;But of course, the correct functioning of a system is more essential than a few “milliseconds”.

Typing &#039;===&#039; in case of typeof and &#039;string&#039; type usually means that developer did not understand very well JS and he/she wrote it is this way &#039;just to be sure&#039;.</description>
		<content:encoded><![CDATA[<p>That&#8217;s cool. I also completely agree with this sentence:<br />
&#8220;But of course, the correct functioning of a system is more essential than a few “milliseconds”.</p>
<p>Typing &#8216;===&#8217; in case of typeof and &#8216;string&#8217; type usually means that developer did not understand very well JS and he/she wrote it is this way &#8216;just to be sure&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dmitry A. Soshnikov</title>
		<link>http://dmitrysoshnikov.com/notes/note-2-ecmascript-equality-operators/comment-page-1/#comment-7269</link>
		<dc:creator>Dmitry A. Soshnikov</dc:creator>
		<pubDate>Sun, 11 Sep 2011 14:36:16 +0000</pubDate>
		<guid isPermaLink="false">http://dmitrysoshnikov.com/?p=1484#comment-7269</guid>
		<description>@&lt;b&gt;John Merge&lt;/b&gt;

Yes, that&#039;s it; thanks for the test, I corrected the sentence to reflect the things in more accurate way.</description>
		<content:encoded><![CDATA[<p>@<b>John Merge</b></p>
<p>Yes, that&#8217;s it; thanks for the test, I corrected the sentence to reflect the things in more accurate way.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

