# Does the hashbang syntax work within eval / Function?

**URL:** <https://es.discourse.group/t/does-the-hashbang-syntax-work-within-eval-function/1897>\
**Category:** I have questions\
**Created:** [January 16, 2024, 4:15am UTC](https://es.discourse.group/t/does-the-hashbang-syntax-work-within-eval-function/1897 "2024-01-16T04:15:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kavi](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kavi/32/1972_2.png) [@kavi](https://es.discourse.group/u/kavi)\
**Post date:** [January 16, 2024, 4:15am UTC](https://es.discourse.group/t/does-the-hashbang-syntax-work-within-eval-function/1897/1 "2024-01-16T04:15:30Z")

</div>

Hi friends, in this link [GitHub - tc39/proposal-hashbang: #! for JS](https://github.com/tc39/proposal-hashbang) . 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`](https://tc39.es/ecma262/#prod-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.

---

<div class="post-metadata">

**Author:** ![Josh-Cena](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/josh-cena/32/1408_2.png) [@Josh-Cena](https://es.discourse.group/u/Josh-Cena)\
**Post date:** [January 16, 2024, 4:25am UTC](https://es.discourse.group/t/does-the-hashbang-syntax-work-within-eval-function/1897/2 "2024-01-16T04:25:58Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![kavi](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kavi/32/1972_2.png) [@kavi](https://es.discourse.group/u/kavi)\
**Post date:** [January 16, 2024, 5:10am UTC](https://es.discourse.group/t/does-the-hashbang-syntax-work-within-eval-function/1897/3 "2024-01-16T05:10:42Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [January 16, 2024, 5:31am UTC](https://es.discourse.group/t/does-the-hashbang-syntax-work-within-eval-function/1897/4 "2024-01-16T05:31:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![kavi](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/kavi/32/1972_2.png) [@kavi](https://es.discourse.group/u/kavi)\
**Post date:** [January 16, 2024, 6:28am UTC](https://es.discourse.group/t/does-the-hashbang-syntax-work-within-eval-function/1897/5 "2024-01-16T06:28:05Z")

</div>

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.
