Friday, June 12, 2026
HomeLanguagesJavascriptJavaScript SyntaxError – Illegal character

JavaScript SyntaxError – Illegal character

This JavaScript exception illegal character occurs if there is an invalid or unexpected token that doesn’t belong there in the code.

Message:

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

Error Type:

SyntaxError

Cause of Error: There is an invalid or unexpected token that doesn’t belong there in the code. Check the code for mismatches like a minus sign ( – ) and a dash ( – ) or simple quotes ( ” ) vs non-standard quotation marks ( “ ).

Example 1: In this example, there is not any mismatch, So the error has not occurred.

Javascript




// Valid token
let GFG_colors = ['#002', '#353', '#665'];
console.log(GFG_colors)


Output:

#002,#353,#665

Example 2: In this example, there is a token mismatch, So the error has occurred.

Javascript




// Invalid Token
let GFG_colors = ['#002', '#353', '#665'];
console.log(GFG_colors)


Output(in console):

SyntaxError: Invalid or unexpected token
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32515 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6897 POSTS0 COMMENTS
Nicole Veronica
12013 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12109 POSTS0 COMMENTS
Shaida Kate Naidoo
7019 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6976 POSTS0 COMMENTS
Umr Jansen
6964 POSTS0 COMMENTS