3 ms·
Javascript does have 'use strict' https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode https://developer.mozilla.org/en-US/docs/Web/Jav
by yett 3y ago
Javascript does have 'use strict'
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- andai 3y agoYes! Exactly. However: "use strict"; let undef; let str1 = "hello"; let str2 = str1 + undef; console.log(str2); // -> "helloundefined" Whereas I propose: "use sane"; let undef; let str1 = "hello"; let str2 = str1 + undef; // -> Uncaught TypeError: Cannot append string and undefined console.log(str2); // (code never reaches this point) (I would also settle for "Uncaught ReferenceError: Attempted use of `undef` before initialization.")
- cmrdporcupine 3y agoYeah, JavaScript has a pile of terrible type coercions, implicit conversions and misuse/reuse of operators. It was a bad 90s/00s trend to do this kind of thing; re-use + for string append, or coerce things into strings for convenience. Python and Ruby have their own gotchas, though not as bad. You might enjoy this classic comedy routine: https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat