简体   繁体   English

每当我尝试编译 javascript 代码时,都会出现语法错误

[英]Whenever I try to compile javascript code I get a syntax error

Whenever I try to run my code I keep getting a syntax error the specifics of the error are here: https://i.stack.imgur.com/H73LR.png每当我尝试运行我的代码时,我都会收到语法错误,错误的细节在这里: https://i.stack.imgur.com/H73LR.png

I don't think it has to do anything with the file format because it is in a.js file I also ran a我认为它与文件格式没有任何关系,因为它位于 a.js 文件中,我还运行了一个

antivirus to see if that was causing it( a site online said viruses could cause this error) my code is as follows:杀毒软件看看是否是导致它(在线网站说病毒可能导致此错误)我的代码如下:

const firstName = 'William'; 
const lastname = 'Johnson';

let val;

val = firstName + lastname;

console.log(val)```


Your code looks fine, so I think it's your antivirus causing this problem.您的代码看起来不错,所以我认为是您的防病毒软件导致了这个问题。 Try disabling your antivirus and run your code again.尝试禁用您的防病毒软件并再次运行您的代码。

The image seems you're trying to look up the .js file directly from your browser.该图像似乎您正在尝试直接从浏览器中查找.js文件。

You can't look up a .js file directly from your browser, the browser can't parse it.您无法直接从浏览器中查找.js文件,浏览器无法解析它。

You should create an HTML file ie a .html file and link your script to it.您应该创建一个HTML文件,即.html文件并将您的脚本链接到它。

Eg In your HTML file例如在您的 HTML 文件中


<!Doctype html>
<html>
    <head>
        <script src="your script source.js"></script>
    </head>
</html>


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每当我尝试在 Visual Studio 代码上运行“npm install”时出现错误 - I get an error whenever i try to run "npm install" on visual studio code 每当我尝试在 VScode 终端中运行 cypress run --record --key xxxx 时,都会收到一条错误消息 - I get an error message whenever I try to run the cypress run --record --key xxxx in VScode terminal 每当我尝试启动我的 discord 机器人时,我都会收到一条错误消息:ReferenceError: Discord is not defined - Whenever I try to start my discord bot I get an error that says: ReferenceError: Discord is not defined CSS 语法错误,当我尝试在刹车中编写代码时 - CSS syntax error in CodeSandBox when i try to write code in a brakets 第二次提交后,每当尝试获取登录页面或注册页面时,我都会收到404错误 - I get a 404 error whenever i try to get login page or signup page, after I did my second commit 每当我尝试从 UserData 获取值时,ThreeJS 返回 undefined - ThreeJS returning undefined whenever I try to get a value from UserData 每当我尝试运行 Cypress Suite 时都会出现以下错误 - Getting below error whenever I try to run Cypress Suite 当我尝试在JavaScript中解析JSON时为什么会出错 - Why I get error when I try to parse JSON in the JavaScript 每当我尝试在邮递员中发出帖子请求时,我都会收到错误消息“Todo 验证失败:任务:需要路径 `task`” - whenever I try to make a post request in postman i get error "Todo validation failed: task: Path `task` is required" 每当我尝试启动我的 discord 机器人时,我都会收到一条错误消息,它显示 ReferenceError: client is not defined,因此我的机器人不会启动 - I get a error message whenever I try and start my discord bot it says ReferenceError: client is not defined, and my bot wont start because of that
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM