On JavaScript's Weirdness
11–20 of 85 posts
Re: On JavaScript's Weirdness
#12> +0 vs. -0
Which feels kind of odd, since that's mostly floating point weirdness, not JS weirdness. Unless they mean the fact that you can force V8 to initialize a zero-value as a double using -0 as a literal (it tends to optimize 0 to integers). But that has no effect on real-world code unless you use Math.sign, or divide by minus zero.
Re: On JavaScript's Weirdness
#13 “JavaScript sucks because '0' == 0!”
- literally everyone ever
I never really understood the hate for this, given that everything is a string in HTTP, and that SQL does the same damn thing. There are far more annoying things about JS (both the language and the ecosystem).Re: On JavaScript's Weirdness
#14Re: On JavaScript's Weirdness
#15“JavaScript sucks because '0' == 0!” - literally everyone ever I never really understood the hate for this, given that everything is a string in HTTP, and that SQL does the same damn thing. There are far more annoying things about JS (both the language and the ecosystem).
Re: On JavaScript's Weirdness
#16I'd forgive a few of those. Unicode is Unicode. The for loop capture behaviour makes sense to me. Missing semis should also be in your linter. Sparse arrays is the sort of feature you'd read up on if you use and not rely on intuition. It makes sense that if you loop over a sparse thing the looping is sparse too.
Since I started using Prettier, I've moved permanently into the no-semicolons camp. Prettier catches ASI hazards and inserts semicolons where needed, and I've never seen it fail. Whichever camp you're in though, put it in your linter, don't leave it to chance. React code is full of array destructuring, that particular hazard is prone to bite you if you ignore it (tho it's still a little contrived if your usual style…
That's it, those are the only 2 edge cases.
Re: On JavaScript's Weirdness
#17 function f1(a:number, b:number, c:number, d:number) {
[a, b] = [b, a]
[c, d] = [d, c]
console.log(a, b, c, d)
}
For the above codes Typescript gives error message: Type 'number[]' is not assignable to type 'number'.Re: On JavaScript's Weirdness
#18Which is why I don't bother reading these posts any more.
Re: On JavaScript's Weirdness
#19Many mistakes in section 2. The author seems to fundamentally misunderstand block scoping vs lexical scoping, and interactions when deferring execution to the next run of the event loop. In the first example: for (let i = 0; i console.log(i)); } // prints "0 1 2" — as expected let i = 0; for (i = 0; i console.log(i)); } // prints "3 3 3" — what? i's scope is outside the for loop in the second example, and the setTime…