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 trialKornel L
4,368 PointsSyntax 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
Michael Braga
Full Stack JavaScript Techdegree Graduate 24,174 PointsBecause 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);
}
}
edinjusupovic
5,664 PointsThe displayQuestion is an object and inside that, you have an anonymous function (unnamed)
Julio Soto
4,544 PointsIs JSON. Look it up. that is how you make any object in Javascript.
Kornel L
4,368 PointsKornel L
4,368 PointsThank You for your answers!