What is the $ symbol used for in JavaScript

前端 未结 3 2004
眼角桃花
眼角桃花 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 22:03

    If you are asking why some variables and function names start with $, then that is simply a convention when using jQuery and/or AngularJS.

    In code that uses jQuery, $ is often used as a prefix for variables that contain jQuery selections. e.g. var $container = $('.container');.

    In AngularJS, they use the $ prefix to mean "core Angular functionality". That way, you know which methods and services are added by the framework, and which are custom to your application.

提交回复
热议问题