JavaScript SyntaxError: Unexpected string — Complete Practical Guide (2026)

You run a script, expect a quick result, and JavaScript stops cold with SyntaxError: Unexpected string. No stack of business logic, no API call, no UI render — just a parser refusing to continue. I have seen this error in tiny snippets, production bundles, generated code, and even in AI-assisted edits where one missing character breaks the entire file. If you are searching for javascript syntaxerror unexpected string 1, you are usually dealing with one core issue: the JavaScript parser encountered a string literal in a spot where grammar rules expected something else.

I treat this error as a grammar failure, not a runtime bug. That mindset changes how fast I fix it. Instead of guessing what variable value caused a problem, I inspect token boundaries: quotes, commas, operators, braces, and identifiers. In this guide, I will show you exactly how I diagnose this error, why the same message appears for different root causes, how to fix each class of mistake, and what guardrails I put in place so teams almost never see it in CI or production again.

What Unexpected string means at parser level

JavaScript engines parse source code before execution. During parsing, the engine checks whether tokens appear in valid order according to language grammar. A string literal token like ‘hello‘ or ‘world‘ is legal only in specific places, such as:

  • Right-hand side expressions (const name = ‘Ada‘)
  • Function arguments (log(‘ready‘))
  • Object property values ({ label: ‘Save‘ })
  • Template literal interpolation contexts (inside ${...} expressions)

You get Unexpected string when a string token appears where the grammar expected another token class, such as:

  • An operator (+, ,, :)
  • An identifier (projectName, userId)
  • A closing delimiter (), ], })
  • End of statement

Think of it like writing an address where city and ZIP are required, but placing a full sentence between them. The words are valid words, but the form rejects their position. JavaScript behaves the same way.

A key point I always remind teams: this is a syntax error. The engine cannot build an executable syntax tree, so the file halts before any runtime branch, network request, or conditional logic can run.

Why the message is sometimes vague

I also want you to know that parser errors are often recovery-based. The engine tries to continue long enough to produce an error location, but it may report the first token it can confidently call wrong, not the original typo. That is why I rarely trust the exact highlighted token as the root cause. I trust it as a starting point.

Reproducing the error in real project scenarios

I rarely debug this from abstract examples. I reproduce failures in contexts that resemble real codebases.

Scenario A: Adjacent strings in configuration

Many config files are just JavaScript objects. A missing comma or plus can produce this error.

const banner = ‘Release‘ ‘2026‘;

Parser expectation: operator between two string expressions.

Scenario B: Invalid declaration from quick refactor

Developers rename variables quickly and accidentally quote an identifier.

let ‘clientName‘ = ‘Northwind Labs‘;

Parser expectation: valid identifier after let.

Scenario C: Broken quote during multiline edit

This one appears all the time when editing log messages.

const note = ‘Deployment complete;

Parser expectation: closing quote before line ends.

Scenario D: Object literal typo that points to string

const theme = {

primary ‘#0f172a‘,

accent: ‘#22c55e‘

};

The parser may point at ‘#0f172a‘ as unexpected string because the missing colon after primary shifts expected tokens.

Scenario E: AI-generated snippet with hidden mismatch

Generated patches can insert mixed quote styles or malformed template literals:

const msg = Build ${status‘ finished;

The engine often reports an unexpected string near the first confusing token, not necessarily where the human mistake started.

In practice, this means you should inspect a few lines before and after the flagged location.

Scenario F: International keyboard and smart quotes

I see this in docs-heavy teams: someone pastes text from a rich editor and gets typographic quotes.

const title = ‘Quarterly Report’;

Those are not ASCII quotes. They look right to humans, wrong to the parser.

Scenario G: Split import statements

Copy-paste can accidentally merge imports.

import ‘./polyfills‘ ‘./monitoring‘;

Parser expectation: semicolon or newline that terminates the first statement.

Case 1: Concatenation without an operator

This is the most common root cause behind javascript syntaxerror unexpected string 1 queries. Two string literals placed side by side are not auto-joined in JavaScript.

Failing example

const greeting = ‘Hello‘ ‘World‘;

console.log(greeting);

Expected parser grammar would require something between these tokens. JavaScript does not treat adjacent string literals as concatenated text.

Correct fixes

I recommend one of these patterns:

1) Use + for simple concatenation:

const greeting = ‘Hello‘ + ‘ World‘;

console.log(greeting);

2) Use template literals for readability:

const greeting = ${‘Hello‘} ${‘World‘};

console.log(greeting);

3) Use array join when building from pieces:

const greeting = [‘Hello‘, ‘World‘].join(‘ ‘);

console.log(greeting);

When I choose each pattern

  • + is fine for one or two static pieces.
  • Template literals are cleaner when variables are involved.
  • join is strongest for dynamic lists and optional segments.

Hidden variant: missing + across lines

This is subtle:

const title = ‘Quarterly‘

‘Report‘;

Automatic semicolon insertion can make this harder to read during debugging. I avoid this style entirely and keep concatenation explicit.

When NOT to use heavy interpolation

I also avoid this pattern when it lowers readability:

const label = ${prefix}${separator}${name}${suffix};

If pieces are optional, join with filter often reads better:

const label = [prefix, name, suffix].filter(Boolean).join(‘ – ‘);

That reduces edit mistakes and makes parser errors less likely.

Case 2: String used where identifier is required

If you place a quoted token where JavaScript expects a variable or function name, the parser throws Unexpected string.

Failing example

let ‘name‘ = ‘Avery‘;

console.log(‘name‘);

Correct version

let name = ‘Avery‘;

console.log(name);

Why this happens in modern teams

I see three common sources:

  • Copying JSON key style into JavaScript declarations
  • Aggressive search-and-replace during refactors
  • AI completions that mix declaration syntax and object syntax

For example, this is valid object syntax:

const profile = {

‘displayName‘: ‘Avery‘

};

But this is invalid declaration syntax:

const ‘displayName‘ = ‘Avery‘;

Practical rule I teach juniors

If the token appears immediately after let, const, var, function, or class, it should almost always be an identifier, not a string literal.

Edge case: destructuring confusion

This is valid and often misunderstood:

const { ‘display-name‘: displayName } = payload;

A string key is valid in object patterns only when mapping from non-identifier keys. The alias (displayName) still must be an identifier.

Case 3: Unterminated or malformed strings

Unclosed strings do not always report as unterminated depending on engine and surrounding code. You may still get Unexpected string when the parser tries to recover and finds another quote later.

Failing example

const message = ‘Hello, World;

console.log(message);

Correct version

const message = ‘Hello, World‘;

console.log(message);

Additional malformed patterns I frequently fix

  • Mixed quote boundaries:

const city = ‘Seattle";

  • Escaped quote missing backslash:

const note = ‘Owner‘s laptop ready‘;

  • Template literal mismatch:

const detail = Status: ${state‘;

Safer alternatives

  • Use template literals when apostrophes are common in text content:

const note = Owner‘s laptop ready;

  • Use editor syntax highlighting aggressively. If colorization looks wrong after a quote, treat it as a parser alarm.
  • Keep Prettier or equivalent format-on-save active. Formatter failures often catch string boundary issues before execution.

Regex literal confusion that looks similar

Sometimes the real problem is not a string literal but a malformed regex that shifts tokenization and causes a later Unexpected string. If a line before the error has /.../ and flags, verify it first.

Advanced triggers you will hit in 2026 codebases

The classic examples are useful, but modern toolchains add new paths to the same parser error.

JSX and TSX expression boundaries

In JSX, text, strings, and JavaScript expressions have strict boundaries.

Bad pattern:

return

Scroll to Top