gpt4 book ai didi

javascript - 语法错误 : Illegal return statement - searching for string in url

转载 作者:行者123 更新时间:2023-12-04 01:50:23 24 4
gpt4 key购买 nike

我现在只是在 Chrome 的控制台中。我创建了这个变量:

url = window.location.href

给出:

网址"http://www.example.com/trips/dest/australia-and-south-pacific/cntry/fiji/ "

现在我尝试了这个:

if (url.indexOf('australia-and-south-pacific') > 0) {return 'foo';}

返回的是:

SyntaxError: Illegal return statement

我希望控制台返回“foo”。

为什么会这样?我注意到在收到此错误后,稍等片刻就会出现一个新错误:

Uncaught TypeError: Cannot read property 'hide' of undefined 

是否有助于诊断?

最佳答案

根据EMCAScript language specification ,

An ECMAScript program is considered syntactically incorrect if it contains a return statement that is not within a FunctionBody.

关于javascript - 语法错误 : Illegal return statement - searching for string in url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25688548/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com