Skip to content

SyntaxError: Unexpected 端的 输入

错误信息

                Unexpected 端的 输入
              

快速摘要

你的 code 有 unclosed bracket, brace, parenthesis, or template literal — JavaScript ran out 的输入虽然 still parsing.

为什么发生

  • Unclosed curly brace { 不使用 matching }

  • Unclosed bracket [ 不使用 matching ]

  • Unclosed parenthesis (不使用 matching)

  • Unclosed template literal (backtick) 不使用关闭 backtick

最小示例

✗ 错误代码
const obj = {
  name: "Ada",
  age: 36
// missing closing brace
✓ 修复代码
const obj = {
  name: "Ada",
  age: 36
};

对象 literal 是 missing 它的关闭 }. 添加它 completes 语法.

如何诊断

  • 检查 for unmatched brackets, braces, and parentheses

  • Use editor 使用 bracket matching 到查找 unclosed pair

  • 运行 code 通过 formatter 到 spot 结构 issues

如何修复

  • 添加 missing 关闭 bracket, brace, or parenthesis

  • 关闭 unclosed template literal 使用 backtick

  • Use linter or formatter 到 identify unclosed delimiter

如何预防

  • Use editor 使用 bracket matching and auto-关闭

  • 运行 linter 到 catch 语法错误 as 你类型

相关资源

相关术语

相关课程

← 返回语言