Problem Description:
When you run the code containing the return statement directly in the script tag or in the browser console, an error is reported:
SyntaxError: Illegal return statement
if (!NaN) {
console.log('went into the conditional statement')
return "Ollie gives!"
}
reason:
In JavaScript, the return statement can only be placed in the function, otherwise the following error will pop up.
SyntaxError: Illegal return statement
Solution:
package the modified code block in function.
(function () {
if (!NaN) {
console.log('went into the conditional statement')
return "Ollie gives!"
}
})()
// Run results
It goes into the conditional statement
"Ollie gives!"
Read More:
- [Solved] Vue gaiters console.log error: Unexpected console statement (no-console)
- Hive Statement Error During Execution: Error while processing statement: FAILED: Execution Error, return code 2 from o
- [Solved] Error while processing statement: FAILED: Execution Error, return code 3 from org.apache.
- [Solved] HiveSQL Error: “Error while processing statement: FAILED: Execution Error, return code 2“
- HIVE Error: Error: Error while processing statement: FAILED: Execution Error, return code 2 from org.apac
- [Solved] error C2041: illegal digit ‘9‘ for base ‘8‘ | error C2059: syntax error: ‘bad suffix on number‘
- [Solved] spring boot – JPA–H2 Error: H2 error: “Syntax error in SQL statement … expected identifier“
- Uncaught SyntaxError: Cannot use import statement outside a module
- [Solved] Vscode1.71.0 terminal error: `sed: illegal option — r`
- The Ajax return value reports an error, and the spring boot development Ajax return value reports an error
- Error: (1, 1) java: Illegal character:’\ufeff’ [How to Solve]
- Implement base64_decode in GO language to solve the problem of illegal characters
- [Solved] jetson nano Error: Illegal instruction(core dumped)
- [Solved] tasm Error: illegal memory reference
- How to Solve ES error: “illegal_argument_exception”
- [Solved] pagehelper Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘LIMIT 1’
- [Solved] Illegal access: this web application instance has been stopped already
- [Solved] std::max() error C2589: ‘(‘ : illegal token on right side of ‘::‘
- [Solved] Springboot WARNING: All illegal access operations will be denied in a future release
- TensorRT model quantization error: Error Code 1: Cuda Runtime (an illegal memory access was encountered)