Famous javascript libraries,
- jQuery
- prototypejs
- mootools
- scriptaculous
all uses $
. What's the significance of $
?
and also, even php uses it to declare variables. I am sure some other languages uses it too.
Famous javascript libraries,
all uses $
. What's the significance of $
?
and also, even php uses it to declare variables. I am sure some other languages uses it too.
It's just a character that can be part of identifiers in JavaScript. No special significance outside of the fact that it's distinctive-looking. It's easy to recognize when you're scanning over code.
Now, in other languages, it can (and does) mean all sorts of things. The term sigil has come into fashion when referring to "special" characters that have syntactic significance in a programming language, specifically as modifying the semantics of a reference to a variable. In JavaScript, I would not use that term for "$" because it doesn't mean anything in particular to the interpreter.
edit — as noted in a comment, "$" has a role in JavaScript regular expression syntax, but I wouldn't consider that related in any way to its use in variable names. (Maybe somebody would; I don't know.)
In Javascript, $ is just another character that can be used in variables. jQuery decided to use that as a short name for the jQuery() function so it will take up less space. Identifiers may consist of letters, digits, and the $ and _ characters
In other languages:
Perl $ in front of a variable means scalar, @ means array, % means hash and & means function. PHP $ means what follows is a variable which could be an object reference. Commodore basic: a trailing $ means it is a string variable. (You didn't need to know that.)
In PHP and Perl, the syntax reveals the details of the identifier so the program is easier to follow. name() name[] $name(), etc. all mean different things which are obvious from the syntax.