Re:Why does `True == False is False` evaluate to False in Py...
by jakear on Saturday May 02, 2020 @11:59AM
(#23052495)
Huh that’s quite interesting. It behaves this way even when you explicitly make it an object literal rather than a block.
I guess JS’s parser explicitly prohibits adding things to a curly-brace enclosed entity?
I’m normally quite defensive of JS, but I’ll have to admit I don’t like that.
Re:Why does `True == False is False` evaluate to False in Py...
by Zarel on Sunday May 03, 2020 @04:16AM
(#23057660)
How did you explicitly make it into an object literal?
({}) + []
-> "[object Object]"
will correctly make it "[object Object]"Did you try to do this?
{a: 1} + []
-> 0
That's interpreted as the statement 1 labeled a, not as an object. This makes it obvious it's not an object: {a: 1, b: 2} + []
-> Uncaught SyntaxError: Unexpected token ':'
JavaScript supports labels so you can continue/break multiple levels at once: {
a: while (true)
while (true)
break a;
}
Re:Why does `True == False is False` evaluate to False in Py...
by jakear on Sunday May 03, 2020 @12:03PM
(#23059823)
Yes, I realized after the fact that I was indeed making a label. I’m now back to not having an issue with JS
Re:Why does `True == False is False` evaluate to False in Py...
by esrauch on Saturday May 02, 2020 @05:26PM
(#23055054)
It's just ASI (automatic semicolon insertion) and at the top-level {} declares a block not an object.
You can also do like ({} + []) and it will actually be "adding" them; the confusion solely comes from people typing into the JS console something that wouldn't make any sense to put into an actual script.
Re:Why does `True == False is False` evaluate to False in Py...
by Non24Throw on Sunday May 03, 2020 @04:13AM
(#23057648)
You’re right! I would never have guessed that. Learn something new every day.
This not really true. Put this js console and you'll see that a is the string "[object Object]":
When you put just {}+[] in your console its doing an empty block followed by unary-plus,like: