简体   繁体   中英

Does the hashbang (#!) have any functionality client side?

I recently learned about the hashbang syntax for writing comments in JavaScript, and need to know if it is or has the potential to be any different then just putting a // at the top of a file. Are there any conventions associated with the hashbang?

I am referring to usage in a browser environment only , not in a shell or NodeJS, etc.

I am asking because I am writing about JavaScript syntax and need to make sure it is 100% correct.

Hashbang has no meaning to JavaScript, as far as it's concerned it's just a comment. The only reason it exists is because Unix treats files beginning with #! specially when you try to run them as commands, and this can be used to run node.js automatically on a server.

This is meaningless in a browser, which loads scripts explicitly. So The hashbang has no special function on the client.

No, #! doesn't have any JavaScript functionality, neither on the server nor on the client side. It's just a comment that does nothing. It has a functionality in executable files on some operating systems, but that has nothing to do with JavaScript - it's just to allow writing JavaScrit scripts as text files that make use of this operating system functionality.

On a related note, JavaScript does also use<!-- … and --> as comment syntax , which is equally useless in non-HTML context like in serverside javascript, but it's permitted for compatibility anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM