Hashbang comments
Hashbang comments allow JavaScript files to begin with a Unix-style #! line. This helps the same file work both as a command-line script and as JavaScript source.
Overview
Hashbang comments allow JavaScript files to begin with a Unix-style #! line. This helps the same file work both as a command-line script and as JavaScript source.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 74 | 79 | 67 | 13.1 | 74 | 13.4 | |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Syntax
JAVASCRIPT
#!/usr/bin/env node
console.log('Hello from CLI!'); Use cases
CLI entry files
Keep a script executable from the command line while still parsing as standard JavaScript.
Cross-environment tooling
Use one entry file for local tooling where both shell execution and JavaScript parsing matter.
Cautions
- Hashbang comments are mainly about interoperability; they do not add runtime capability in the browser.
- Only the very first line is treated specially, so placement matters.
Accessibility
- This feature does not affect UI accessibility directly, but consistent tooling can improve developer workflows.
- Document command-line usage clearly so scripts remain understandable to contributors.
Related links
Powered by web-features