coderef

Hashbang commentsBaseline · Widely available

The #! comment at the absolute start of a script or module is treated as a normal comment and is ignored by the JavaScript engine.

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Mar 24, 2020. Widely available since Sep 24, 2022.

Browser support

DesktopChrome
1–73Not supported
74+Supportedsince Apr 23, 2019
Current: 155
Edge
12–18Not supported
79+Supportedsince Jan 15, 2020
Current: 154
Firefox
1–66Not supported
67+Supportedsince May 21, 2019
Current: 157
Safari
1–13Not supported
13.1+Supportedsince Mar 24, 2020
Current: 27
MobileChrome Android
18–73Not supported
74+Supportedsince Apr 24, 2019
Current: 155
Firefox Android
4–66Not supported
67+Supportedsince May 21, 2019
Current: 157
Safari iOS
1–13Not supported
13.4+Supportedsince Mar 24, 2020
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: Lexical grammar#hashbang comments.

Feature detection

JS · check before using
// Syntax can't be tested with an if-statement — an unsupported
// browser fails to parse the whole script. Either transpile for older
// targets (e.g. Babel/TypeScript/esbuild), or probe in isolation:
let supported = true;
try {
  new Function("/* code that uses the syntax */");
} catch {
  supported = false;
}

This is a language syntax feature.