2016-12-30 8 views
3

자바 스크립트 객체 (http://javascriptissexy.com/javascript-objects-in-detail/)에 대한 기사를 읽었으므로 다음 코드를 메모장에 복사하여 ++ (버전 55.0)에서 실행했습니다. 2883.87 ㎛). 콘솔을 열면 콘솔에서 SyntaxError를보고합니다. 누군가가 왜 그런 생각을 갖고 있습니까? 모든게 괜찮아 보인다. 당신이 모든 것을 복사하면Javascript - 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 
+0

어디에서 실행 했습니까? 브라우저 (어느 쪽)에서, nodejs에서, 완전히 다른 무엇인가? – UnholySheep

+1

콘솔에 코드를 복사하여 붙여 넣을 때 2 개의 보이지 않는 문자가 보였습니다 - 그 이유는 –

+1

복사/붙여 넣기가 오류를 일으킬 수있는 보이지 않는 문자를 선택할 수 있습니다. 코드를 직접 입력하십시오. – Pointy

답변

6

그냥 붙여 콘솔에 쓰기, 당신은 실제로 당신이 점점 오류에 Invalid or unexpected token있는 코드에서 일부 유니 코드 문자 (\u200b)이있는 당신을 볼 것이다 그들은 간격 폭 제로이기 때문에, 그래서 그냥 그들을 제거하고 완벽하게 실행됩니다 코드가

// 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

당신은 찾을 수 있습니다 아래와 같이 그들을 볼 수 없습니다 제로 너비 공백 문자에 대한 자세한 내용은 여기를 참조하십시오. http://www.fileformat.info/info/unicode/char/200b/index.htm