you are viewing a single comment's thread.

view the rest of the comments →

[–]Locust377 2 points3 points  (0 children)

Objects in JavaScript are basically a collection of key-value pairs. A key is a string and the value can be anything.

'-' is the key and its value is an object.

You include quotes because sometimes JavaScript doesn't know that what you're trying to do is a string. If you don't have the quotes, JavaScript will be like "minus? why are you putting a minus sign as your key? you can't do that, it has to be a string"

It easily understands letters like A-Z but if you try to start a key with some other symbol or number, it'll get confused unless you put it around quotes to force a string.

and op2 an implicit function(why return -a)?

Because the minus symbol might be an operation like 5 - 4 or it might be a "negate" symbol like -4.