javascript - chrome 无法运行 console.log() Uncaught SyntaxError: Invalid or unexpected token
问题描述
那是我的html代码
<body>
<script src="../js/myjscode.js"></script>
</body>
这是 myjscode.js
function firstFunction() {
console.log("
hello world ");
}
firstFunction();
如果我console.log("hello world ");
输入myjscode.js
是完美的输出hello world
但如果我输入
function firstFunction() {
console.log("
hello world ");
}
firstFunction();
在 myjscode.js 上
它显示在 chrome 控制台上
Uncaught SyntaxError: Invalid or unexpected token
我做错了什么?
解决方案
那是因为当您console.log()
在Uncaught SyntaxError: Invalid or unexpected token
. 要解决这个问题,请使用反引号而不是引号:
function firstFunction() {
console.log(`
hello world`);
}
firstFunction();
推荐阅读
- selenium - Selenium - 上传多个文件会导致上传重复文件(第一个文件一次又一次)
- reactjs - React 站点 - 刷新时,Auth Route 无权访问 auth 上下文数据
- python - 如何将元组保存到 sys.stdin 中的某个变量
- javascript - JS - 如何在同一选项卡中打开一个 url,然后在 3 秒后重定向到另一个 url
- python - 创建一个 numpy 数组的置换浅表副本
- python - 从 tkinter 中删除多个标签
- ios - 如何使用启动故事板或 XIB?
- flutter - 更改从外部类返回的抽屉小部件的抽屉图标
- python - 如何使用假设检验来比较组
- java - 无法在 ajax 覆盖弹出窗口中单击或发送键,并使用 selenium 和 java 显示 Element not Intractable 异常