SyntaxError: Illegal 返回语句
错误信息
Illegal 返回语句
快速摘要
你 used `返回` 之外的 函数请求体 — 返回是 仅有效内部函数.
为什么发生
Used 返回 at 顶部 level 的 script (不内部函数)
Used 返回内部如果块 那个是 不内部函数
Accidentally placed 返回语句之外函数请求体
最小示例
✗ 错误代码
const x = 5;
return x;✓ 修复代码
function getValue() {
const x = 5;
return x;
}返回是 仅有效内部函数. Wrap code in 函数到 use 返回.
如何诊断
查找返回语句 mentioned in 错误
检查如果它 是内部函数请求体
Look for misplaced 返回语句 in code 结构
如何修复
Move 返回语句内部函数
移除返回如果它 是不 intended 到是 in 函数
Wrap code in 函数如果返回是 需要
如何预防
总是 use 返回内部函数 bodies 仅
Use linter 到 catch illegal 返回语句