$$ prefix in AngularJS is used as a private variable, as it is responsible for preventing accidental code collision with the user code.
Whereas, $ prefix is used to define angular core functionalities such as variable, parameter, property or method, etc.
In AngularJS, the $
and $$
prefixes are conventionally used for specific purposes:
- $ Prefix:
- The
$
prefix is commonly used for built-in AngularJS services, such as$http
,$scope
,$timeout
, etc. These services are part of the AngularJS framework, and using the$
prefix helps distinguish them from custom variables or services.
Example:
javascriptmyApp.controller('MyController', ['$scope', function($scope) {
$scope.message = 'Hello, AngularJS!';
}]);
- The
- $$ Prefix:
- The
$$
prefix is reserved for AngularJS internal properties or functions. These are considered private and are not intended for regular use in application code. They might be used by AngularJS itself for managing its internal state.
Example:
javascriptvar internalVariable = angular.$$minErr('myModule');
- The
It’s important to note that using the $$
prefix for your own variables or services is not recommended, as it may lead to naming conflicts with future versions of AngularJS or cause unintended behavior.