I am playing with a javascript and am running into an error. The error is this:
Invalid left-hand side expression in postfix operation.
And the script is long but I think this is this issue. The weird thing is this works when I run it locally, but when it is packaged, using asset_packager, it fails.
Any ideas why I might be getting this error?
UPDATE: After doing more research I found this function. The error seems to happen after in the "while" statement and I assume it's the "++ + a + ". This is a plugin so I didn't want to go messing with the code...but do you thing this could be it?
m.getInternetExplorerMajorVersion = function() {
var a = m.getInternetExplorerMajorVersion.cached = typeof m.getInternetExplorerMajorVersion.cached != "undefined" ? m.getInternetExplorerMajorVersion.cached : function() {
var a = 3, b = d.createElement("div"), c = b.getElementsByTagName("i");
while ((b.innerHTML = "<!--[if gt IE "++ + a + "]><i></i><![endif]-->") && c[0])
Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
;
return a > 4 ? a : !1
}();
return a
}
The "Invalid left-hand side in assignment" error occurs when we have a syntax error in our JavaScript code. The most common cause is using a single equal sign instead of double or triple equals in a conditional statement. To solve this, make sure to correct any syntax errors in your code.
The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. For example, a single = sign was used instead of == or === .
Left Hand Side. In JavaScript, you may hear the expressions "left side" or "right side" when talking about declarations. These refer to evaluations or comparisons, and to which side the particular expression is on.
A single “=” sign instead of “==” or “===” is an Invalid assignment.
You didn't say which plugin was that but I was dealing with the same problem, Jeffrey, with I think the same plugin, because my code was looking almost the same.
I followed your lead. The plugin was History.js, from page: https://github.com/browserstate/History.js/ and I was using bundled html4+html5 version, which was minimized.
I changed that fragment
innerHTML="<!--[if gt IE "+ ++a+"]><i></i><![endif]-->"
into
innerHTML="<!--[if gt IE "+ (++a)+"]><i></i><![endif]-->"
And it did the job!
I started to wonder what exactly problem lied in. The most important suspect was of course minification "compression". In normal situation following code is correct
var a=0; "begining of string "+ ++a+" the rest of string";
And returns "begining of string 1 the rest of string"
However the minification gets rid of white space and turns it into something that is understood by a browser as a:
var a=0;"begining of string "+++a+" the rest of string";
What gives us error Uncaught ReferenceError: Invalid left-hand side expression in postfix operation
EDIT: As Sam pointed out, the issue was caused by minifcation, and not than gzip compression, of course :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With