I was wondering whether execution of these two has any difference to the JS interpreter. is this because we can not create and call method on object simultaneously.? Any help on this?
Asked
Active
Viewed 64 times
-1
-
I'm sure this has been answered somewhere... Just gotta find it – Cerbrus Nov 16 '17 at 08:53
-
1try this: `({}).toString()` :) – Poul Kruijt Nov 16 '17 at 08:54
1 Answers
2
Because JavaScript will interpret your curly brace as a block, not an object. Try with:
({}).toString()

Faly
- 13,291
- 2
- 19
- 37
-
_"JavaScript code can't start with a curly brace."_ isn't true. `{}+[]` is a valid JavaScript statement. – Cerbrus Nov 16 '17 at 08:57
-
2"JavaScript code can't start with a curly brace" — It can. It just isn't an object, so you can't call methods on it. – Quentin Nov 16 '17 at 08:58
-
-
1And now this answer is correct, but inferior to those in the dupe target. – Cerbrus Nov 16 '17 at 09:00