let arr = ['a','b','c']
for( let i=0;i<=arr.length;i++){
if (i ==2 ){
console.log(arr[i])
return // error: Uncaught SyntaxError: Illegal return statementcan only be used in functions
}
}
Return can only be used in functions
function run() {
let a = 1
if (a == 1) {
return
}
console.log(2); // will not output, return interrupts the execution of the code that follows
}
Read More:
- [Solved] Uncaught SyntaxError: Cannot use import statement outside a module
- js: SyntaxError: Cannot use import statement outside a module
- JS async await Error: Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules
- [Solved] SyntaxError: Cannot use import statement outside a module
- [Solved] Uncaught SyntaxError: The requested module does not provide an export named
- [Solved] Uncaught SyntaxError: Invalid Unicode escape sequence
- [Solved] SyntaxError: Cannot use import statement outside a module
- [Solved] ajax Error: Uncaught SyntaxError: Unexpected end of JSON input
- [Solved] SyntaxError: Cannot use import statement outside a module
- vue Error: Uncaught SyntaxError: Invalid shorthand property initializer
- [Solved] Uncaught SyntaxError: Unexpected token ‘<‘
- [Solved] Binding onclick event in JS: for loop: error uncaught typeerror: cannot set properties of undefined (setting ‘classname’)
- node.js yarn Error: SyntaxError: Unexpected string [How to Solve]
- [Solved] SyntaxError: E:\IdeaProject\src\main.js: Identifier ‘ElementPlus‘ has already been declared
- [Solved] JS Error: Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)
- JS bug Log Uncaught TypeError: Cannot read property ‘previoustSibling‘ of null
- [Solved] Turf.js error: uncaught (in promise) error: the solution of invalid unit
- [Solved] echarts Draw Errror: echarts-d9fd185e.js:31447 Uncaught (in promise) Error: Initialize failed: invalid dom.
- About JS error uncaught syntax error: invalid shorthand property initializer
- request.js?b775:101 Uncaught (in promise) Error: Failed to convert value of type ‘java.lang.String’ to required type ‘java.lang.Long’;