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) Practice Project User Interface Code

Kornel L
Kornel L
4,368 Points

Syntax question

displayQuestion: function() { this.populateIdWithHTML("question", quiz.getCurrentQuestion().text); },

I don't understand the : in the syntax, before the function. What is it? Why is it there? Shouldn't it be = ? Can someone explain it please? Thank You!

3 Answers

Because we are using an Object Literal (due to the open and end braces)

var objectLiteral = {}; // I am an object literal

we assign our properties and methods with : and not =

var objectLiteral = {
  name: 'Michael',  //property
  greet: function() {  //method
    console.log(this.name);
  }
}

Using an = when assigning a property or method within an Object Literal will produce an error

var objectLiteral = {
  name = 'Michael',  //Error :(
  greet = function() {  //Error :(
    console.log(this.name);
  }
}
Kornel L
Kornel L
4,368 Points

Thank You for your answers!

The displayQuestion is an object and inside that, you have an anonymous function (unnamed)

Julio Soto
Julio Soto
4,544 Points

Is JSON. Look it up. that is how you make any object in Javascript.