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.
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.
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.
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.
Symbols are created with Symbol() call with an optional description (name).
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With