MENU
Hashbang
Command-line scripts on Unix-like systems traditionally begin with a hashbang (or 'shebang') line, #!, telling the shell which interpreter should run the file — eg. #!/usr/bin/env node at the very top of a Node.js script, so that ./script.js can be executed directly without typing 'node' first. Since this is not valid JavaScript syntax, engines previously had to special-case or strip it outside the language proper.
ECMAScript 2023 standardized this as part of the grammar itself: if the very first two characters of a script or module are #!, the entire first line is treated as a single-line comment, exactly like a line starting with //. The hashbang is only meaningful on the first line, at the first character — a #! appearing anywhere else is simply a syntax error.
cli-script.js:
#!/usr/bin/env node
console.log('running as a CLI script');This is purely a grammar accommodation for tooling (bundlers, CLI frameworks) — the hashbang itself has no runtime effect inside the JavaScript engine; the operating system's shell is what actually reads it to decide which interpreter to launch.