Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: Improve note on forcing string comparison #1526

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

<p>Given the above definition of equality:</p>
<ul>
<li>
String comparison can be forced by: `"" + a == "" + b`.
String comparison can be forced by: `\`${a}\` == \`${b}\``.
This conversation was marked as resolved by ljharb

This comment has been minimized.

Copy link
@ljharb

ljharb May 2, 2019

Member

the old example is still true; perhaps instead of replacing it, we could include both?

This comment has been minimized.

Copy link
@shvaikalesh

shvaikalesh May 2, 2019

Author Contributor

Old example is not idiomatic ToString conversion: "" + a calls ToPrimitive without a hint, while template literal passes "string" hint. This is important is a is an object with both valueOf and toString, or defines @@toPrimitive.

This comment has been minimized.

Copy link
@ljharb

ljharb May 2, 2019

Member

That’s true; i suppose this is indeed the only syntactic way to force ToString (otherwise you’d need String(a) === String(b))

</li>
<li>
Numeric comparison can be forced by: `+a == +b`.
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.