TechCodex@programming.dev to Programmer Humor@lemmy.mlEnglish · 1 year agoJavascript can create atomic bombsprogramming.devimagemessage-square44fedilinkarrow-up1494arrow-down134
arrow-up1460arrow-down1imageJavascript can create atomic bombsprogramming.devTechCodex@programming.dev to Programmer Humor@lemmy.mlEnglish · 1 year agomessage-square44fedilink
minus-squareadrian783@lemmy.worldlinkfedilinkarrow-up1·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
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