21

"Understanding Js"

Comments
  • 0
    Repost
  • 3
    "Not knowing about strict equality and how to use a weakly typed language"
  • 4
    Use === everywhere. Problem solved.
  • 0
    In javascript, == means "similar". Equality as in mathematical property of sets is transitive, therefore something non-transitive can't be equality. Btw use === please.
  • 2
    I 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.
  • 0
    WTF I HAVE SEEN THIS A MILLION BILLION TIMES ON DEVRANT. REPOST!!!!
  • 0
    @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 ===
  • 0
    == 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
  • 1
    don't compare those two then... why would you even compare a string to an empty array
  • 0
    Anyone who thinks this is weird/funny/ridiculous, does not have a fundamental understanding of JavaScript.
Add Comment