Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does several javascript libraries use $ for one or other use

Tags:

javascript

I have seen several javascript libraries using $ be it jQuery , mootools , prototype etc also even some of the books on javascript recommend using $ as a function replacement of document.getElementById. is it just a random thing.

like image 830
sushil bharwani Avatar asked Jul 01 '10 07:07

sushil bharwani


People also ask

Why JavaScript libraries are used?

Similarly, a JavaScript library has codes or functions that developers can reuse and repurpose. A developer writes these codes, and other developers reuse the same code to perform a certain task, like preparing a slideshow, instead of writing it from scratch. It saves them significant time and effort.

Why are there different JavaScript frameworks?

Each JavaScript framework serves a different purpose. Building web apps and websites from start to finish can take quite a bit of work. Web frameworks – or really, JavaScript frameworks – take advantage of the fact that every website and web app have common features.

Can you use multiple JavaScript frameworks?

Projects In JavaScript & JQuerynoConflict() method allows you to use multiple frameworks, while using jQuery. Other JavaScript frameworks include Ember, Angular, Backbone, etc.


1 Answers

The reason $ was actually introduced as a valid variable name in the ECMA specs was to distinguish machine generated code from human written code .
Most JS libraries use $ because it is very rare that you would want to name some of your variable $ and hence it would avoid collision and accidental overwriting of the variable . ( However now since every library is using $ , if you want to use two libraries , you are in a soup ) .

like image 170
NM. Avatar answered Nov 15 '22 22:11

NM.