What is the $ symbol used for in JavaScript

前端 未结 3 1996
眼角桃花
眼角桃花 2020-12-04 20:57

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?

3条回答
  •  春和景丽
    2020-12-04 21:38

    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).

提交回复
热议问题