Buttons ( @Buttons@programming.dev ) English45•5 months ago Lunya \ she/it ( @backhdlp@iusearchlinux.fyi ) 29•5 months agoI still don’t understand the
===
operatorEdit: I think a more type strict
==
? Pretty sure I understand the point of typescript now. QuazarOmega ( @QuazarOmega@lemy.lol ) 42•5 months ago> 1 == 1 true > 1 == '1' true > 1 === '1' false
(from node REPL)
Basically it’s the real equals sign
frezik ( @frezik@midwest.social ) 28•5 months agoThe short answer is that your language needs === when it fucked up the semantics of ==, but it’s also too popular and you can’t fix it without breaking half the web.
Mikina ( @Mikina@programming.dev ) 12•5 months agoIt’s also important if you’re checking hashes (at least, it was - if you’re using correct hashing algorithm that isn’t ancient, you will not have this problem).
Because if you take for example “0e462097431906509019562988736854” (which is md5(“240610708”), but also applicable to most other hashing algorithms that hash to a hex string), if(“0e462097431906509019562988736854” == 0) is true. So any other data that hashes to any variantion of “0e[1-9]+” will pass the check, for example:
md5("240610708") == md5("hashcatqlffzszeRcrt")
that equals to
"0e462097431906509019562988736854" == "0e242700999142460696437005736231"
which thanks to scientific notation and no strict type checking can also mean
0462097431906509019562988736854 == 0242700999142460696437005736231
which is
0 == 0
`I did use md5 as an example because the strings are pretty short, but it’s applicable to a whole lot of other hashes. And the problem is that if you use one of the strings that hash to a magic hash in a vulnerable site, it will pass the password check for any user who’s password also hashes to a magic hash. There’s not really a high chance of that happening, but there’s still a lot of hashes that do hash to it.
frezik ( @frezik@midwest.social ) 1•5 months agoIf you’re checking passwords, you should be using constant time string checking, anyway.
More likely, you should let your bcrypt library do it for you.
Limitless_screaming ( @Limitless_screaming@kbin.social ) 12•5 months ago==
but for JavaScript. What you don’t understand is the==
of JavaScript. kevincox ( @kevincox@lemmy.ml ) 11•5 months agoJS’s
==
has some gotchas and you almost never want to use it. So===
is what==
should have been.All examples are true:
"1" == true [1, 2] == "1,2" " " == false null == undefined
It isn’t that insane. But some invariants that you may expect don’t hold.
"" == 0 "0" == 0 "" != "0"
BougieBirdie ( @Bougie_Birdie@lemmy.blahaj.zone ) English4•5 months agoThe other comments explains it in pretty good detail, but when I was learning my teacher explained it sort of like a mnemonic.
1 + 1 = 2 is read “one plus one equals two”
1 + 1 == 2 is read “one plus one is equal to two”
1 + 1 === 2 is read “one plus one is really equal to two”
And you hit the nail on the head, is that === is type explicit while == is implicit.
bobbykjack ( @bobbykjack@programming.dev ) 2•5 months agoI’d use something like:
= becomes
== equals
=== is identical to
It’s funny how everyone thinks “equals” in this context should be “identical to” when, in normal language, it doesn’t really mean that at all!
✂⚋⚋⚋⚋ clb92 ⚋⚋ ( @clb92@feddit.dk ) English3•5 months agoLike
==
but more strict. The==
operator will do type conversion, so0 == ''
will actually be true, as an example. Sometimes (honestly, most times) you may want to compare more strictly.See this StackOverflow answer: https://stackoverflow.com/questions/359494/which-equals-operator-vs-should-be-used-in-javascript-comparisons
luciole ( @luciole@beehaw.org ) 12•5 months agoI wish the assignment operator wasn’t the equal sign.
QuazarOmega ( @QuazarOmega@lemy.lol ) 19•5 months agox 👈 5
xedrak ( @xedrak@kbin.social ) 13•5 months agoOk deal, but that means we need to change the equality operator to 👉👈
OpenStars ( @OpenStars@startrek.website ) English5•5 months agoYou sonnofabitch I’m in!:-P
OpenStars ( @OpenStars@startrek.website ) English8•5 months agox 🔫 5
the pew pew principle /s
Malgas ( @Malgas@beehaw.org ) English8•5 months agoInterpreter: Wait, x is 5?
This code: Always has been.
OpenStars ( @OpenStars@startrek.website ) English4•5 months agoIt is now, if you know what’s good for you.
cerement ( @cerement@slrpnk.net ) 10•5 months ago:=
MxM111 ( @MxM111@kbin.social ) 4•5 months agoThat’s delayed assignment.
cerement ( @cerement@slrpnk.net ) 6•5 months agoprocrastination assignment
expr ( @expr@programming.dev ) 1•5 months agoIn Haskell, it’s the same as the mathematical
=
symbol.
callyral [he/they] ( @callyral@pawb.social ) English9•5 months ago1+1====2!
← dreamberd developer gandalf_der_12te ( @gandalf_der_12te@feddit.de ) 6•5 months agoBasically Java in a nutshell
Blackmist ( @Blackmist@feddit.uk ) English8•5 months agoJS devs should have a font that turns == into ≈.
DrunkenPirate ( @DrunkenPirate@feddit.de ) 8•5 months agoChatGpt: 1+1≈2
OpenStars ( @OpenStars@startrek.website ) English2•5 months agoReddit: 1+1=your muther (sic, x2)
X: 1+1≈we should violently overthrow the government
4chan: nvm, I don’t want to get banned for saying this one
Darkaga ( @Darkaga@kbin.social ) 2•5 months ago4chan: “Gamer words”
OpenStars ( @OpenStars@startrek.website ) English2•5 months agoNo, that’s Discord 🙃
xedrak ( @xedrak@kbin.social ) 5•5 months agocries in PHP
tiredofsametab ( @tiredofsametab@kbin.social ) 2•5 months ago1 + false ? (I have no idea in which order JS would evaluate things as I rarely have to touch that language much anymore)
I Cast Fist ( @ICastFist@programming.dev ) 2•5 months agoDon’t forget that
_.isFinite('1')
returns true ;) Tyfon ( @Tyfon@programming.dev ) 2•5 months agoI’m JavaScript developer. I love coding WebApps. JS sucks💩.
thericcer ( @thericcer@reddthat.com ) 1•5 months agoAny Verilog devs?