Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the $ symbol used for in JavaScript

I am a JavaScript learner and have been researching this matter, but with no success. What is the $ symbol used for in JavaScript besides regular expressions? Any resources or readings regarding this would be appreciated. Thanks.

like image 806
Babiker Avatar asked Jun 24 '10 06:06

Babiker


People also ask

What are symbols used for in JS?

Symbols are often used to add unique property keys to an object that won't collide with keys any other code might add to the object, and which are hidden from any mechanisms other code will typically use to access the object. That enables a form of weak encapsulation, or a weak form of information hiding.

What is symbol () using for?

for() The Symbol. for(key) method searches for existing symbols in a runtime-wide symbol registry with the given key and returns it if found. Otherwise a new symbol gets created in the global symbol registry with this key.

What does AT symbol mean in JavaScript?

The @ symbol in javascript stands for a decorator. Decorators are not present in ES6 so the in code you are working with the decorator is probably transpiled to an version of javascript which can be run in any browser.

Which symbol is optional in JavaScript?

Symbols are created with Symbol() call with an optional description (name).


Video Answer


1 Answers

It doesn't mean anything special.

But because $ is allowed in identifier names, many Javascript libraries have taken to using $ as the "central" interface to them, or at least as a shortcut for accessing their functionality.

For example, if you're using jQuery and you say $("div"), this is a call to the $ function with argument "div". When you say $.post(), it's calling the post method on the $ object (Javascript is nice in that functions are first-class objects).

like image 111
Dean Harding Avatar answered Sep 18 '22 11:09

Dean Harding