Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
In javascript, == means "similar". Equality as in mathematical property of sets is transitive, therefore something non-transitive can't be equality. Btw use === please.
-
ltlian21885yI hate how I know why that is the case as well.
I honestly can't think of any scenario where you specifically want to use == over ===. Whenever I see fuzzy equality in JS I'm legitimately intrigued by the author's motivations, as if he knows something about the complex internal implementations of the operator that I don't. -
josap2115y@ltlian once I almost got in a situation where I needed == in TS.
Long story short, I was checking the value returned by a method over which I did not have control (for various reasons), so even if I passed a int (1), I could get "1" (not always) as a consequence of user interaction (input field).
Initially I did use ==, but then it felt so wrong that I redesigned the thing just to be sure that int would be int, and I happily used === -
h3kt1c014105y== only matches value
=== Matches value and type
It's logical that 0 == []
And "0" != []
Think that an empty array is null, and 0 is also null , but strings are not null
Also repost -
don't compare those two then... why would you even compare a string to an empty array
-
-AJ-2325yAnyone who thinks this is weird/funny/ridiculous, does not have a fundamental understanding of JavaScript.
"Understanding Js"
joke/meme