ros*_*s-u 4 javascript syntax-error object-literal console.log
我正在阅读有关Javascript Objects(http://javascriptissexy.com/javascript-objects-in-detail/)的文章,因此我将以下代码复制粘贴到我的Notepad ++中并在Chrome中运行(版本55.0.2883.87 m) .打开控制台后,控制台会报告SyntaxError.有人知道为什么吗?一切似乎都好.
// 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
Run Code Online (Sandbox Code Playgroud)
小智 7
如果你复制刚刚粘贴的所有内容并将其写入控制台,你会发现\u200b
你的代码中有一些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
Run Code Online (Sandbox Code Playgroud)
您可以在此处找到有关零宽度空格字符的更多信息:http://www.fileformat.info/info/unicode/char/200b/index.htm