Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

What is the purpose of the dollar sign before the variable scope i.e. $scope?

What does the $ sign as the first character of a variable mean?

In what context?

Some people use it to convey a meaning but as far as JavaScript is concerned it is just another valid identifier.

From MDN Identifier

In JavaScript, identifiers can contain only alphanumeric characters (or "$" or "_"), and may not start with a digit. An identifier differs from a string in that a string is data, while an identifier is part of the code. In JavaScript, there is no way to convert identifiers to strings, but sometimes it is possible to parse strings into identifiers.

Hey Dave,

I only asked because I am doing the angular tutorial and a parameter was named $scope and I just thought it was a special icon for a special type of variable. Thanks for replying :)

Aha, that's why I asked about context.

Looks like the angular peeps use do use it - some searching should help you see what and why they use it - I'm not up on angular so will stop babbling now :tropical_drink: :palm_tree:

1 Answer

Words prefaced with a dollar sign ($) in Angular are custom objects within the Angular engine ,similarly to jQuery where $() is reference to a jQuery Object, which in turn typically references a DOM element.

Info on Scopes in Angular: Angular: What are $scope's