0

In some tutorial for AngularJS online, I saw $promise or $checkSessionServer are declared in a way of

var $promise=$http.post('data/user.php',data);

I learned that AngularJS declare using $, but I can not find those $ variables in native AngularJS function / variables at all!

Is this something old or else?

Thanks

ey dee ey em
  • 7,991
  • 14
  • 65
  • 121
  • You can name a variable whatever you want, but since angular does use that convention, it is recommended to not name them like that. – lucuma Jul 16 '14 at 17:00
  • `$promise` here is a custom variable by the author of the application, plugin, etc. [The `$` is a valid character in identifiers](http://stackoverflow.com/questions/205853/why-would-a-javascript-variable-start-with-a-dollar-sign); it isn't an operator as you might find in other languages. It isn't part of AngularJS itself. – Jonathan Lonowski Jul 16 '14 at 17:00
  • @Jonathan Lonowski What is the difference if I just rename the var into, for example, promise and declare it instead use var promise? Will there be any difference? – ey dee ey em Jul 16 '14 at 17:31
  • 1
    @Chen Any references to the variable will also need to be revised since `$promise` and `promise` are completely distinct names to JavaScript, but you can choose to name the variable [any valid *Identifier*](http://ecma-international.org/ecma-262/5.1/#sec-7.6) you desire (`$foo`, `bar$baz`, etc.). Also, not sure if you were suggesting this or not, but [with or without `var`](http://stackoverflow.com/questions/1470488/what-is-the-function-of-the-var-keyword-in-ecmascript-262-3rd-edition-javascript) is separate from how its named and will affect the scope of the variable. – Jonathan Lonowski Jul 16 '14 at 18:00

0 Answers0