Micah Micah - 2 months ago 10
Javascript Question

What does ':' (colon) do in JavaScript?

I'm learning JavaScript and while browsing through the jQuery library I see

:
(colon) being used a lot. What is this used for in JavaScript?

// Return an array of filtered elements (r)
// and the modified expression string (t)
return { r: r, t: t };

Answer
var o = {
    r: 'some value',
    t: 'some other value'
};

is functionally equivalent to

var o = new Object();
o.r = 'some value';
o.t = 'some other value';