javascript - How come "minus, space, minus" evaluates to the "plus" operator? -


node -e 'console.log(- -1)' // prints 1 makes sense 

however:

node -e 'console.log(1 - - 1)' // prints 2 not make sense me 

integer - - integer magically converts "minus, space, minus" "plus" operator. why?

update: seems wasn't clear enough. question not why double negative in mathematics evaluate positive how magically evaluates + operator; these 2 different scenarios - making negative number positive 1 thing, invoking implicitly + thing.

makes perfect sense, double negative in mathematics evaluate positive


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -