How to understanding the expression "{} == true"?

<p>I try to understanding the expression <code>{} == true</code> following the section <code>7.2.12</code> of doc <a href="http://ift.tt/AmLIEB"><code>Ecma-262</code></a>.</p><blockquote><ol start="9"><li>If Type(y) is Boolean, return the result of the comparison <code>x == ToNumber(y)</code></li></ol></blockquote><p>The result of <code>ToNumber(true)</code> is <code>1</code>, then</p><p><code>{} == 1</code></p><blockquote><ol start="11"><li>If Type(x) is Object and Type(y) is either String, Number, or Symbol, then return the result of the comparison <code>ToPrimitive(x) == y</code>.</li></ol></blockquote><p>I am confused at the <code>ToPrimitive({})</code> now.</p><blockquote><ol start="3"><li><p>If hint is "string", then</p><p>a. Let methodNames be «"toString", "valueOf"».</p></li><li><p>Else,</p><p>a. Let methodNames be «"valueOf", "toString"».</p></li></ol></blockquote><p><strong>Should <code>ToPrimitive({})</code> be interpreted as <code>{}.toString()</code> or <code>{}.valueOf()</code>?</strong></p><p>Suppose the <code>toString()</code> is called.</p><blockquote><p>If Type(x) is String and Type(y) is Number, return the result of the comparison <code>ToNumber(x) == y</code></p></blockquote><p>So <code>{} == true</code> could be <code>ToNumber(ToPrimitive({})) == ToNumber(true)</code>?</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34525917/how-to-understanding-the-expression-true">http://ift.tt/1RQXrg2</a></h2>

Nhận xét

Bài đăng phổ biến từ blog này

Align div to bottom of the page in bootstrap

Align elements inside an tag vertically

Javascript is unable to stop page loading