6 ms·
There’s a few condescending answers here. You will find this more common in weakly typed languages like PHP and VB and maaaaaybe JavaScript, where null == “null
by hsbauauvhabzb 2y ago
There’s a few condescending answers here. You will find this more common in weakly typed languages like PHP and VB and maaaaaybe JavaScript, where null == “null” will probably evaluate to true.
- deleted 2y ago[deleted]
- IggleSniggle 2y agojs doesn't have this particular problem, but it does have both `null` and `undefined`, which will have varying semantically different usages depending on local conventions. For example, some will prefer to use `null` to mean that a value is _intentionally_ missing (for example, the db explicitly returned a null value), while `undefined` does not have any such connotation. These exist for frontend engineers to navigate decisions often far removed from their influence. Anyway, `null != ''` and `null != 'null'`, but `null == undefined`. However, `null !== undefined`. A lot has been made of js Truthy/Falsy equality operator, but most js programmers will take steps to actively avoid it coming into play. Probably the `void` operator is still under-used though in frontend code, though, since there's some pretty surprising legacy things that can happen when interacting with DOM APIs (like `checkbox.onclick = () => doSomething()` resulting in different checkbox behavior depending on whether or not `doSomething` returns a boolean or undefined).
- hsbauauvhabzb 2y agoI would call myself a relatively good developer and I fully understood type checking occurred via ===, and compare by value caught me. In my defence, I assumed this was less of an issue in modern JS, but thou shall not break backward comparability, apparently.
- koakuma-chan 2y agoI treat usage of `==` in JavaScript as undefined behavior.
- Sohcahtoa82 2y agoI kinda want to change my middle name to "undefined" now. I wonder if I could legally define my middle name as starting with a lowercase letter.
- mrunkel 2y agoI can confirm that PHP doesn't have this problem. <?php if ("null" == null) { echo "true"; } else { echo "false"; } prints "false"
- hsbauauvhabzb 2y agoIs this php5 or a more recent version? That is hugely relevant when it comes to pho and something I should have mentioned in my original post (no idea if this specific thing would work in pho5, but there are other weird things)
- mrunkel 2y agoI tested "all supported" but this is explicitly for 5: https://3v4l.org/cFc5I#v5.4.45 https://3v4l.org/cFc5I#v5.4.45