JavaScript SyntaxError: Unexpected identifier
A plain-words explanation of this JavaScript message: what it means, the usual causes, and the steps that fix it.
The messageUncaught SyntaxError: Unexpected identifier 'b'
Make the error yourself
Run in Google Chrome 157.0.8103.51. This is the smallest example we could find that shows it.
JavaScript (in a script tag)
const a = 1 b = 2;
console.log(a, b);Browser console (the real message)
SyntaxError: Unexpected identifier 'b'Why it happens
The engine found a name (an identifier) where the grammar of the language does not allow one. The message gives the name, and the mistake is usually just before it: a missing comma in a list or object ({ a: 1 b: 2 }), a missing operator (a b), a missing ; or newline between two statements on one line, or a misspelt keyword (fucntion greet()). In the example two statements have been written on one line without a separator.
How to fix it
- Look at the code just before the name in the message.
- In lists and objects, check that every item is followed by a comma.
- Separate statements with a semicolon or a new line.
- Check the spelling of keywords:
function,const,return,async.
The corrected version
JavaScript (in a script tag)
const a = 1;
const b = 2;
console.log(a, b);Browser console (the corrected version)
1 2How to avoid it
Use a formatter and a linter. They mark missing commas and keywords at once.
Questions
Is a missing semicolon always an error?
No. JavaScript inserts semicolons at line ends in most cases, but not when two statements are on one line.
This is an independent guide. It is not connected with Python, Microsoft, Google, GitHub or the Git project. Product names belong to their owners. Examples were run on 13 November 2026 in a practice folder or a blank workbook; your version may word a message slightly differently.