I get the following error when trying to increment a value obtained from a map in the console in Chrome (50.0.2661.86):
Uncaught ReferenceError: Invalid left-hand side expression in postfix operation(…)
And similar in Node (4.4.3):
ReferenceError: Invalid left-hand side expression in postfix operation
at repl:1:3
at REPLServer.defaultEval (repl.js:262:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:431:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:211:10)
at REPLServer.Interface._line (readline.js:550:8)
at REPLServer.Interface._ttyWrite (readline.js:827:14)
The offending code is:
var m = new Map()
m.set(1, 0)
m.get(1)
var n = m.get(1)++ // Uncaught ReferenceError: Invalid left-hand side expression in postfix operation(…)
The following also fail:
var n = ++m.get(1)
var n = ++(m.get(1))
A bug in V8 maybe? Or a misunderstanding in what's happening syntax-wise with the ++
operator?