So there are dozens of questions with this title, however, all answers I could find seem to mention some hacks working in some specific cases but not being helpful in others. Many are concerned with jQuery or Ajax, yet the problem is pure JavaScript arising at very basic level:
function f() {
false || (return true);
}
This function declaration (without execution) throws
Uncaught SyntaxError: Unexpected token return
in Chrome and
SyntaxError: Return statements are only valid inside functions
in Safari. However this function doesn't:
function f() {
false || (a=true);
return true;
}
Anybody can explain this strange behaviour?
Luckily, the SyntaxError: Unexpected token error is relatively easy to fix. In most cases, the error can be resolved by checking the code for accuracy and correcting any mistakes. There are also a number of tools and resources available to help you debug and fix JavaScript code.
To solve the "Uncaught SyntaxError: Unexpected identifier" error, make sure you don't have any misspelled keywords, e.g. Let or Function instead of let and function , and correct any typos related to a missing or an extra comma, colon, parenthesis, quote or bracket.
The error Uncaught SyntaxError: Unexpected token < is most commonly caused by your site's code referring to an asset that is no longer available. Most commonly, this is due to a filename change in assets generated during your build.
Because return
is not an expression, but it expects an expression:
function f() {
return false || true;
}
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