SyntaxError: illegal character
SyntaxError: Invalid character (Edge) SyntaxError: illegal character (Firefox) SyntaxError: Invalid or unexpected token (Chrome)
There is an invalid or unexpected token that doesn't belong at this position in the
code. Use an editor that supports syntax highlighting and carefully check your code
against mismatches like a minus sign (
- ) versus a dash (
or simple quotes (
" ) vs non-standard quotation marks (
Some characters look similar, but will cause the parser to fail interpreting your code. Famous examples of this are quotes, the minus or semicolon (greek questionmark (U+37e) looks same).
“This looks like a string”; // SyntaxError: illegal character // “ and ” are not " but look like this 42 – 13; // SyntaxError: illegal character // – is not - but looks like this var foo = 'bar'; // SyntaxError: illegal character // <37e> is not ; but looks like this
This should work:
"This is actually a string"; 42 - 13; var foo = 'bar';
It's easy to forget a character here or there.
var colors = ['#000', #333', '#666']; // SyntaxError: illegal character
Add the missing quote for
var colors = ['#000', '#333', '#666'];
When copy pasting code from external sources, there might be invalid characters. Watch out!
var foo = 'bar'; // SyntaxError: illegal character
When inspecting this code in an editor like Vim, you can see that there is actually a zero-width space (ZWSP) (U+200B) character.
var foo = 'bar';<200b>