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 Ember.js Controllers Controller Properties

Rushan Mohamed
Rushan Mohamed
553 Points

Are Properties similar to Javascript Variables?

Thank you for the great video. I have a small doubt. Are Properties similar to Javascript Variables?

2 Answers

Chris Shaw
Chris Shaw
26,676 Points

Hi Rushan,

Properties are similar but in a set context they aren't, variables by default are defined in the global scope of the page which is always window, setting a variable here allows us to access it's value from anywhere within our code without any need to pass it from function-to-function for example.

However a variable can also be scoped therefore you can't always trust that it exists everywhere in your code which is how properties work, a property is a name-spaced value that requires you to define the scope before it can be accessed and used. Properties are unique in that way.

All-in-all they both do the same thing, the way they work makes them different.

Rushan Mohamed
Rushan Mohamed
553 Points

Got it Chris, thank you for the clear answer.

In a way yes but my understanding of it is a property will hold data about an object, and an object is a variable.

So if you wanted a "house" object, a property of house might be number of rooms.

You could assign a value to the room number of the object "house" like this:

house:rooms = 5;

Check out the w3 they go into more detail than I ever could as I'm a bit new to JavaScript !

Rushan Mohamed
Rushan Mohamed
553 Points

Thank you. I'll check the W3 as well