Does the hashbang syntax work within eval / Function?

Hi friends, in this link GitHub - tc39/proposal-hashbang: #! for JS . Though They mentioned

Hashbang comments are only available at the start of a Script or Module parsing goal. Since eval uses Script it does support Hashbang comments. Since Function uses FunctionBody, it does not.

Does But why they mentioned "hashbang syntax work within eval / Function" in title? . An example for this sentence will be helpful for this beginner.

eval(`#!hello
console.log(1);`); // works

Function(`#!hello
console.log(1);`)(); // SyntaxError
1 Like

Thank you. One more clarity needed .So as a hashbang syntax eval will work. But in unix type systems while using cli , for example file with name hi.js with the following code.

eval(#!/usr/bin/env node console.log(1););

will work normal when we use command ,

node hi.js

because hashbang is considered as comment .
but will not work for the command as interpreter path when using within eval

./hi.js

so need some clarity on this. what's the concept/rule here or what's happening here?

In order to be executable like that, a file needs to start with an actual hashbang, not in eval - the point of the proposal was to make these files valid JavaScript, where previously they were not.

1 Like

Thank you. now i am able to understand the difference of hashbang line in cli and hashbang comment in javascript. For me both replies are solution.