本文介绍了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);
输出:
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控制台中的意外标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!