On JavaScript's Weirdness
a year ago
- #JavaScript
- #Programming Quirks
- #ECMAScript
- JavaScript's `eval` function behaves differently when renamed, accessing only the global scope instead of the current scope due to a special case in ECMAScript's specification.
- JavaScript loops exhibit unique behavior with variable capturing: variables defined in the loop header are treated as if captured by value, while those defined outside are captured by reference.
- There exists a falsy object in JavaScript, `document.all`, which is specified in the ECMAScript standard for backward compatibility with old Internet Explorer code.
- String iteration in JavaScript can yield different counts based on the method used, due to the mix of UTF-16 code units, Unicode code points, display characters, and extended grapheme clusters.
- Sparse arrays in JavaScript, created by omitting elements or using the `Array` constructor, can lead to unexpected behavior with array methods and have poor performance.
- Automatic Semicolon Insertion (ASI) in JavaScript can lead to unexpected interpretations of code, as demonstrated by the example where missing semicolons change the code's behavior.