SyntaxError: illegal character

๋ฉ”์„ธ์ง€

SyntaxError: Invalid character (Edge)
SyntaxError: illegal character (Firefox)
SyntaxError: Invalid or unexpected token (Chrome)

์—๋Ÿฌ ํƒ€์ž…

๋ฌด์—‡์ด ์ž˜๋ชป๋˜์—ˆ์„๊นŒ?

์ฝ”๋“œ์— ํ•ด๋‹น ๊ตฌ๋ฌธ์— ๋งž์ง€ ์•Š๊ฑฐ๋‚˜ ์˜ˆ๊ธฐ์น˜ ์•Š์€ ํ† ํฐ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋งˆ์ด๋„ˆ์Šค ๊ธฐํ˜ธ( - )์™€ ๋Œ€์‹œ( โ€“ ) ๋˜๋Š” ๋”ฐ์˜ดํ‘œ( " )์™€ ๋น„ํ‘œ์ค€ ๋”ฐ์˜ดํ‘œ( โ€œ ) ๋“ฑ์ด ์ž˜๋ชป ์‚ฌ์šฉ๋œ ๊ฒฝ์šฐ์— ๋Œ€ํ•ด ๋ฌธ๋ฒ• ์ฒดํฌ๋ฅผ ํ•ด์ฃผ๋Š” ํŽธ์ง‘๊ธฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ฝ”๋“œ๋ฅผ ์ฃผ์˜ ๊นŠ๊ฒŒ ํ™•์ธํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์˜ˆ์ œ

์ž˜๋ชป ์‚ฌ์šฉ๋œ ๋ฌธ์ž

์ผ๋ถ€ ๋ฌธ์ž๋“ค์€ ๋น„์Šทํ•˜๊ฒŒ ๋ณด์ด์ง€๋งŒ ํŒŒ์„œ๊ฐ€ ์ฝ”๋“œ ํ•ด์„์„ ์‹คํŒจํ•˜๊ฒŒ ๋งŒ๋“ญ๋‹ˆ๋‹ค. ์œ ๋ช…ํ•œ ์˜ˆ๋กœ ๋”ฐ์˜ดํ‘œ, ๋งˆ์ด๋„ˆ์Šค ๋˜๋Š” ์„ธ๋ฏธ์ฝœ๋ก (greek questionmark (U+37e)๊ณผ ๋™์ผํ•˜๊ฒŒ ๋ณด์ž…๋‹ˆ๋‹ค)์ด ์žˆ์Šต๋‹ˆ๋‹ค.

โ€œThis looks like a stringโ€;  // SyntaxError: illegal character
                             // ๋น„์Šทํ•ด ๋ณด์ด์ง€๋งŒ โ€œ์™€ โ€๋Š” "์ด ์•„๋‹™๋‹ˆ๋‹ค

42 โ€“ 13;                     // SyntaxError: illegal character
                             // ๋น„์Šทํ•ด ๋ณด์ด์ง€๋งŒ โ€“์€ -์ด ์•„๋‹™๋‹ˆ๋‹ค

var foo = 'bar'อพ             // SyntaxError: illegal character
                             // ๋น„์Šทํ•ด ๋ณด์ด์ง€๋งŒ <37e>์€ ;์ด ์•„๋‹™๋‹ˆ๋‹ค

์•„๋ž˜ ์˜ˆ์ œ๋Š” ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘ํ•ฉ๋‹ˆ๋‹ค:

"This is actually a string";
42 - 13;
var foo = 'bar';

์ผ๋ถ€ ํŽธ์ง‘๊ธฐ์™€ IDE๋Š” ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ๋ถ€๋ถ„์„ ์•Œ๋ ค์ฃผ๊ฑฐ๋‚˜ ์ ์–ด๋„ ๊ฐ•์กฐ ํ‘œ์‹œ๋ฅผ ํ•ด์ฃผ์ง€๋งŒ ์ „๋ถ€๋Š” ์•„๋‹™๋‹ˆ๋‹ค. ์ด๋Ÿฐ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ–ˆ์„ ๋•Œ ๋ฌด์—‡์ด ๋ฌธ์ œ์ธ์ง€ ์ฐพ์„ ์ˆ˜ ์—†๋Š” ๊ฒฝ์šฐ, ๋ฌธ์ œ๊ฐ€ ์žˆ๋Š” ์ค„์„ ์ง€์šฐ๊ณ  ๋‹ค์‹œ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ ๊ฐ€์žฅ ์ข‹์Šต๋‹ˆ๋‹ค.

๋ฌธ์ž ๋น ํŠธ๋ฆฌ๊ธฐ

์•ž์ด๋‚˜ ๋’ค์— ์˜ค๋Š” ๋ฌธ์ž๋ฅผ ์žŠ์–ด๋ฒ„๋ฆฌ๊ธฐ ์‰ฝ์Šต๋‹ˆ๋‹ค.

var colors = ['#000', #333', '#666'];
// SyntaxError: illegal character

 '#333'์— ๋น ์ง„ ์ž‘์€๋”ฐ์˜ดํ‘œ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

var colors = ['#000', '#333', '#666'];

์ˆจ๊ฒจ์ง„ ๋ฌธ์ž

๋‹ค๋ฅธ ๊ณณ์—์„œ ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌํ•˜์—ฌ ๋ถ™์—ฌ๋„ฃ์€ ๊ฒฝ์šฐ ์ž˜๋ชป๋œ ๋ฌธ์ž๊ฐ€ ํฌํ•จ๋ผ ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ฃผ์˜ํ•˜์„ธ์š”!

var foo = 'bar';โ€‹
// SyntaxError: illegal character

Vim๊ณผ ๊ฐ™์€ ํŽธ์ง‘๊ธฐ์—์„œ ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ฒดํฌํ•˜๋ฉด ํญ ์—†๋Š” ๊ณต๋ฐฑ(zero-width space (ZWSP) (U+200B)) ๋ฌธ์ž๊ฐ€ ์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

var foo = 'bar';โ€‹<200b>

๊ฐ™์ด ๋ณด๊ธฐ