Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pound Sign (#) As Comment Start In JavaScript?

Does the pound sign (#) start a comment in JavaScript? I have a website I am using with NPM and when I tried to minify the JavaScript with Grunt, Uglify threw the error:

Warning: Uglification failed.
Unexpected character '#'.
Line 1 in app/min-libs/node_modules/grunt-contrib-jshint/node_modules/jshint/nod
e_modules/cli/examples/cat.js
 Use --force to continue.

The file name being referred to seems to be from another NPM module, meaning they know what they are doing. So when I went to app/min-libs/node_modules/grunt-contrib-jshint/node_modules/jshint/node_modules/cli/examples/cat.js, the offending line says:

#!/usr/bin/env node

Is this a comment or do the owners of this NPM module know some super-secret forbidden JavaScript technique?

like image 603
trysis Avatar asked Jan 10 '14 05:01

trysis


People also ask

What is the pound sign?

The symbol £, representing the pound sterling. (US) The symbol #, denoting weight in pounds.

How do I type pound sign?

Inserting the pound symbol using an Alt keyboard shortcutPress and hold Alt + 0163 or Alt + 156 on the numeric keypad.

What does the '#' mean?

The symbol # is known variously in English-speaking regions as the number sign, hash, or pound sign. The symbol has historically been used for a wide range of purposes including the designation of an ordinal number and as a ligatured abbreviation for pounds avoirdupois – having been derived from the now-rare ℔. #

Does a pound sign have 2 lines?

The sign may be drawn with one or two bars depending on personal preference, but the Bank of England has used the one-bar style exclusively on banknotes since 1975.


1 Answers

It is not a JavaScript technique, but a *nix OS one. It is called shebang. Quoting from Wiki

Under Unix-like operating systems, when a script with a shebang is run as a program, the program loader parses the rest of the script's initial line as an interpreter directive; the specified interpreter program is run instead, passing to it as an argument the path that was initially used when attempting to run the scrip

So, the cat.js file can be executed in the shell, like an executable (if it has executable permission).

cat.js

instead of

node cat.js
like image 77
thefourtheye Avatar answered Sep 25 '22 10:09

thefourtheye