3 ms·
You like JavaScript, the language where parenthesizing an expression can change the value of that expression[1]: > {} + [] <- 0 > ({} + []) <- "[obje
by deathanatos 10y ago
You like JavaScript, the language where parenthesizing an expression can change the value of that expression[1]:
> {} + []
<- 0
> ({} + [])
<- "[object Object]"
or how the identity x|0 == x doesn't hold for all "integers"[2]:
> 4294967296 | 0
<- 0
or how function definitions aren't grammatically statements, making this[3]:
function foo() {
function bar() {} // legal
if(1) {
function baz() {} // illegal!
}
}
this just always bites me:
> "a string" instanceof String
<- false
(but seriously, I don't understand why JavaScript needed the object/primitive distinction. I get it for Java, but not in JS.)
> sometimes I feel that the language works against you, and not with you.
JavaScript is the language where you ask it, "here, I want to know which of these guns most adequately shoots my foot."
ES6 improves things considerably; in 10 years we'll have good browser support for basic data structures, like Map and Set.
[1]: I'm joking. Read it first, then return to this footnote. The sleight of hand is this: the first expression parses as an empty code block, followed by a unary plus taking an empty list. The second parses as binary addition. There's also a terrible amount of coercion taking place. This also "means" that binary addition "isn't" commutative: {}+[] and []+{} evaluate to different values; the same trickery is involved.
[2]: the binary or operator, |, silently converts the operands to a signed 32bit integer for the duration of the expression. Note that signed 32bit integer is a type not available to the JavaScript programmer — it only arises internally! (The only numerical type available is "Number", which is an IEEE double.)
[3]: the grammar for functions is essentially "list of statements or function definitions", so function definitions are only valid at the "top level" of a function.
- dvt 10y agoTrue, JS is a pain in the butt. But I think it's fun: it feels fluid and that you can do almost "anything" with it (for better or worse). In Python, I feel that I'm fighting against arbitrary goalposts or that I'm wracking my brain parsing some logical puzzle (like in the PEP example).
- secstate 10y agoProperly spec'd and implemented language structures are the opposite of logical puzzles. JS is not fluid, it's broken.