TechCodex@programming.dev to Programmer Humor@lemmy.mlEnglish · 1 year agoJavascript can create atomic bombsprogramming.devimagemessage-square38fedilinkarrow-up1426arrow-down135
arrow-up1391arrow-down1imageJavascript can create atomic bombsprogramming.devTechCodex@programming.dev to Programmer Humor@lemmy.mlEnglish · 1 year agomessage-square38fedilink
minus-squareadrian783@lemmy.worldlinkfedilinkarrow-up3·edit-21 year ago2 equal signs will coerce the second operand into the type of first operand then do a comparison of it can. so 1 == “1” is true. this leads to strange bugs. 3 equal signs do not do implicit type conversion, cuts down on weird bugs. 1===“1” is false. edit: it appears to be more complicated than that for double equals and the position of operands don’t matter. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality
minus-squareTonyTonyChopper@mander.xyzlinkfedilinkarrow-up1·1 year agowow that seems super useful, thanks
2 equal signs will coerce the second operand into the type of first operand then do a comparison of it can. so 1 == “1” is true. this leads to strange bugs.
3 equal signs do not do implicit type conversion, cuts down on weird bugs. 1===“1” is false.
edit: it appears to be more complicated than that for double equals and the position of operands don’t matter. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality
wow that seems super useful, thanks