{Carrer web log} ←
About the dollar sign ($) in JavaScript
Friday, October 15, 2010 { 11 Comments }
I’m writing this short post because I think that many people are puzzled by the $ sign in JavaScript. When I started using jQuery I thought that the $ sign have some super powers or do some Voodoo magic.The truth is the dollar sign is "special" in JavaScript but unfortunately doesn’t do Voodoo 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.
This standard specifies specific character additions: The dollar sign ($) and the underscore (_) are permitted anywhere in an IdentifierName.
…
What other characters(letters) are there?
Recently I discovered that you can use some small Ancient Greek letters Alpha, Beta, Delta and others (α, β, δ) can be used.
So var α = "hello world"; is ok. Unfortunately there is no Alpha (α ) sign on my keyboard.
Potentially this Greek letters can be used to avoid "conflicts" or in some minification tools but that is probably another topic.
Did I missed something?
Update: I was wrong that the the jQuery was first implement the $ sign. But my point was not who was the first or last but the explain that the $ is just like any other letter in JavaScript.
11 Responses to “About the dollar sign ($) in JavaScript”
- // MichalBe // 10/15/2010
- // Vladimir // 10/15/2010
- // Rob Mills // 10/15/2010
- // // 10/15/2010
-
// Poetro
// 10/15/2010
"Potentially this Greek letters can be used to avoid "conflicts" or in some minification tools but that is probably another topic."
The problems with the Greek letters and minification is that they comsume 2 bytes and may not be compatible with every browser. It is better to be safe with 2 ASCII character variable names, as they also consume 2 bytes then any other character, and it could also be better compressed with gzip. -
//
// 10/18/2010
Interesting article.
However, some corrections though (not to what the $ is for in JavaScript).
- Is not 'woody' magic, is 'Voodoo' magic.
- You spelled "java script" and then "javascript", I think is 'JavaScript'.
- Be consistent. Try typing 'jQuery' right every time (there's a JQuery in your text). I assume you're a programmer/coder... you can't type wrong when programing, otherwise your application won't work.
Thanks. -
// Vladimir
// 10/18/2010
@Anonymous: First, thank you! I really appreciate your comment. I will update this post with yours suggestions. I usually make grammatical and other mistakes when I'm doing fast post like this. Other thing I'm little dyslexic and I'm not coming from English speaking country. But that doesn't excuse me at all. I should be definitely more careful when posting. Making "cheap" typos make my blog post and me not professional and not serious so I will try to avoid that.
- // Unknown // 10/18/2010
-
// Vladimir
// 10/18/2010
@Jason: That was in the previous version of ECMA-262 (Archive Version) http://www.ecma-international.org/publications/standards/Ecma-262-arch.htm. From Section 7.6: "The dollar sign is intended for use only in mechanically generated code."
Today the latest version of this Ecma Standard dosen't say anything about "mechanically generated code". Here is the PDF of latest Ecma Standard http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf (chapter 7.6) - // // 10/19/2010
- // Unknown // 7/06/2014
<< Home
About Me <<<
Name: Vladimir Carrer
vladocar [at] gmail.com
Location: Verona, Italy
I'm a web designer, developer, teacher, speaker, generally web addicted ...
My projects <<<
- AI Prompt Directory
- Hand Drawn Icons
- Font Design Inspiration
- Font Pairings
- Free SVG Cut File
- Upcoming NFT projects
- Discord Tutorials
- Free Sublimation Designs
- Tech Feed
- MySQL Lite Administrator
- Quark Mini PHP CMS
- Formy - CSS Form Framework
- Emastic - CSS Framework
- Malo - CSS Library
- The Golden Grid
- 1 line CSS Grid Framework
- Two Lines CSS Framework
- Child Selector System - CSS Framework
- Better Web Readability Project
- Azbuka - CSS Typographical Base Rendering Library
- ClipR - bookmarklet for better reading
- CSS3 Action Framework
- CSS Mini Reset
- HTML5 Mini Template
- CSS Mobile Reset
- picoCSS - JavaScript Framework
- HTML Lorem Ipsum Crash Test
- Object Auto Documentation - JavaScript
- o - JS Library for Object Manipulation
- Foxy - CSS Framework
- Tumblr Free Theme - Better Readability Project
- Box - CSS Framework
- SMART CSS GRID
- nanoJS - Minimal JS DOM Library
- Flexy CSS Framework
- Katana is CSS Layout System made with Flexbox
- Micro CSS Reset
- 60 Grid System
- Simple CSS Button
- ramd.js JavaScript library for making web applications.
- Minimal Notes web app build with Vue.js
- Scribble Font for Prototyping & Wireframing
- Flex One - 1 CSS Class System
- Floaty - CSS Float Based Layout System
- Infinity CSS Grid
- CLI Convert websites into readable PDFs
- keywords-extract - CLI tool, extract keywords from any web page.
- screenshoteer - Make website screenshots and mobile emulations from the command line.
- Basic.css - Classless CSS Starter File
§§Previous Posts <<<
- Canvas Grid - JS1K entry
- I have great startup idea: It’s Hacker News ReDesign
- Fireworks Mini Web Wireframing Kit
- iPhone Wireframe Kit - Google Docs
- HTML5 Mini Template
- GReadable - readability bookmarklet for Google Re...
- TweetThisPage - bookmarklet for fast twitter posting
- Bulletproof CSS3 media queries
- Distributed Color Palette – Photoshop Tool
- iPhone Grid System
Other Profiles <<<
Content is licensed under a Creative Commons Public Domain License