This is a mirror of official site: http://jasper-net.blogspot.com/

About the dollar sign ($) in javascript

| Sunday, October 17, 2010
I’m writing this short post because I think that many people are puzzled by the $ sign in java script. When I started using jQuery I thought that the $ sign have some super powers or do some woody magic.

The truth is the dollar sign is "special" in javascript but unfortunately doesn’t do woody magic.

Why the $ sign is special?

Because you can do this: var $ = "Hello World";

But you can’t do this: var £ = "Hello World"; or var @ = "Hello World"; or var # = "Hello World";

The $ sign is "special" because is treated like any normal letter (a,b,c …).

So the $ is cool sign that probably every keyboard have and is perfectly legal to use. Probably because of that John Resig decided to give him special role in JQuery and later the $ sign was implemented by Prototype and MooTools. How jQuery and the other libraries implement the $ is another issue which will not be discussed in this article.

Another characters like the ($) dollar is the underscore (_).

Quote from Standard ECMA-262 ECMAScript Language Specification

7.6 Identifier Names and Identifiers
Identifier Names are tokens that are interpreted according to the grammar given in the “Identifiers” section of chapter 5 of the Unicode standard, with some small modifications. An Identifier is an IdentifierName that is not a ReservedWord (see 7.6.1). The Unicode identifier grammar is based on both normative and informative character categories specified by the Unicode Standard. The characters in the specified categories in version 3.0 of the Unicode standard must be treated as in those categories by all conforming ECMAScript implementations.

Read more: Carrer web log

Posted via email from .NET Info

0 comments: