"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.")
Yeah, 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.