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

Non-strict comparison of a number to true (1 == true) #135

Closed
markogresak opened this issue Dec 23, 2019 · 4 comments
Closed

Non-strict comparison of a number to true (1 == true) #135

markogresak opened this issue Dec 23, 2019 · 4 comments
Assignees
Labels
new-example A proposal of the new example released Issues and PRs released by semantic-release

Comments

@markogresak
Copy link

I was goofing around with JS weirdness today, and I found this behaviour, which took me some time to explain to myself. Maybe it could be included in the file?

It started off with the basic type coercion, which worked as expected:

1 == true
// true
0 == false
// true

My initial assumption was that the value is cast to Boolean. For this simple example, that assumption would hold

Boolean(1)
// true
Boolean(0)
// false

But it broke when trying the following:

1.1 == true
// false

Given my original assumption, I was a bit confused because I know Boolean(1.1) -> true.

But the true explanation to the first snippet is:

Number(true)
// 1
Number(false)
// 0

Meaning that true/false is cast to and compared as Number.

@libook
Copy link
Contributor

libook commented Dec 25, 2019

Boolean(1.1)
// true

Hum... interesting.

@denysdovhan
Copy link
Owner

@markogresak could you open a PR?

@denysdovhan denysdovhan self-assigned this Feb 5, 2021
@denysdovhan denysdovhan added the new-example A proposal of the new example label Feb 5, 2021
@denysdovhan
Copy link
Owner

Added with an explanation. Will be published soon.

github-actions bot pushed a commit that referenced this issue Feb 6, 2021
# [1.17.0](v1.16.0...v1.17.0) (2021-02-06)

### Bug Fixes

* Lint markdown files ([aa26445](aa26445))

### Features

* Add A stringified string example. Close [#113](#113) ([de081e4](de081e4))
* Add alert from hell. Close [#55](#55) ([1d973b9](1d973b9))
* Add an example with arguments. Close [#35](#35) ([1289b0c](1289b0c))
* Add an infinite timeout example. Close [#61](#61) ([f356deb](f356deb))
* Add comparison table. Close [#107](#107) ([c40b0df](c40b0df))
* Add double dot example. Close [#124](#124) ([597b5ee](597b5ee))
* Add example with Math.min and Math.max. Close [#23](#23). ([ad120b2](ad120b2))
* Add Extra Newness. Close [#78](#78) ([81316dc](81316dc))
* Add Split a string by a space. Close [#171](#171) ([827da42](827da42))
* Add Why you should use semicolons. Close [#112](#112) ([7488b34](7488b34))
* Non-strict comparison of a number to true. Close [#135](#135) ([0242818](0242818))
@github-actions
Copy link

github-actions bot commented Feb 6, 2021

🎉 This issue has been resolved in version 1.17.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions github-actions bot added the released Issues and PRs released by semantic-release label Feb 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-example A proposal of the new example released Issues and PRs released by semantic-release
Projects
None yet
Development

No branches or pull requests

3 participants