本文介绍了SyntaxError:Chrome的Javascript控制台中的意外标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Chrome的Javascript控制台中测试了这个javascript,它返回 SyntaxError:Unexpected Identifier
。
I tested this javascript in Chrome's Javascript console and it returned SyntaxError: Unexpected Identifier
.
我从教程中得到了这段代码,只是测试了Chrome的控制台,所以我希望它可以工作,除非我使用控制台错误了吗?
I got this code from a tutorial and was just testing Chrome's console so i expected it to work, unless I'm using the console wrong?
var visitorName = "Chuck";
var myOldString = "Hello username. I hope you enjoy your stay username.";
var myNewString = myOldString.replace ("username," visitorName);
document.write("Old String = " + myOldString);
document.write("<br/>New string = " + myNewString);
输出:
Output:
SyntaxError: Unexpected identifier
推荐答案
逗号被逗号吃掉了!
这部分:
("username," visitorName);
应该是:
("username", visitorName);
除了:对于将代码粘贴到控制台中,您可以一次将它们粘贴到一行中,以帮助您查明出错的地方; - )
Aside: For pasting code into the console, you can paste them in one line at a time to help you pinpoint where things went wrong ;-)
这篇关于SyntaxError:Chrome的Javascript控制台中的意外标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!