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 Object-Oriented JavaScript (2015) Introduction to Methods Understanding this

Why did Andrew remove var when he move the 'var sides= 6' from out of the function?

He removed the 'var' word, when he moved the 'var sides=6' from the function. I don't understand.

1 Answer

andren
andren
28,558 Points

Because he changed it from being a variable to just being a property of the dice object.

Objects have been covered in a previous course so I assume you are somewhat familiar with them. If I wanted to create an object with a property called message that stored "Hello World" it would look like this:

var someObject = {
    message: "Hello World"
}

It would not look like this:

var someObject = {
    var message: "Hello World"
}

Because var is not used when you declare properties in an object. This is also why the roll property that stores the function in the video does not use the var keyword either.

Thank you Andren!