[英]Javascript - SyntaxError: Invalid or unexpected token - while creating object - Invisible character
I was reading the article on Javascript Objects ( http://javascriptissexy.com/javascript-objects-in-detail/ ), so I copy-pasted the following code into my Notepad++ and ran it in Chrome(Version 55.0.2883.87 m). 我正在阅读有关Javascript Objects( http://javascriptissexy.com/javascript-objects-in-detail/ )的文章,因此我将以下代码复制粘贴到我的Notepad ++中并在Chrome中运行(版本55.0.2883.87 m) 。 Upon opening the console, console reports SyntaxError. 打开控制台后,控制台会报告SyntaxError。 Does someone have an idea why? 有人知道为什么吗? Everything seems ok. 一切似乎都好。
// We have been using dot notation so far in the examples above, here is another example again:
var book = {title: "Ways to Go", pages: 280, bookMark1:"Page 20"};
// To access the properties of the book object with dot notation, you do this:
console.log(book.title); // Ways to Go
console.log(book.pages); // 280
If you copy everything you just pasted and write it in the console, you would see that there are some unicode characters ( \
) in your code which are actually the Invalid or unexpected token
in the error that you are getting, you don't see them because they are zero-width spaced, so just remove them and the code would run perfectly as shown below 如果你复制刚刚粘贴的所有内容并将其写入控制台,你会发现你的代码中有一些unicode字符( \
)实际上是你得到的错误中的Invalid or unexpected token
,你没有看到它们是因为它们是零宽度间隔,所以只需删除它们,代码就可以完美地运行,如下所示
// We have been using dot notation so far in the examples above, here is another example again: var book = {title: "Ways to Go", pages: 280, bookMark1:"Page 20"}; // To access the properties of the book object with dot notation, you do this: console.log(book.title); // Ways to Go console.log(book.pages); // 280
You can find more about the zero width space character here: http://www.fileformat.info/info/unicode/char/200b/index.htm 您可以在此处找到有关零宽度空格字符的更多信息: http : //www.fileformat.info/info/unicode/char/200b/index.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.