The below code is perfectly valid in JavaScript :-
( { a:10 , b:20 , c:30 } );
But when do we need such an Object which we can't reference in our code ?
You often use an unnamed literal as a parameter to a function call. A popular example is calling jQuery plugin methods on elements, eg:
$("div").someMethod({prop:'value',otherProp:'value2'});
It is also possible (and often beneficial) to assign such objects to variables beforehand and then passing it in, like so:
var options = {prop:'value',otherProp:'value2'};
$("div").someMethod(options);
But sometimes its just easier and cleaner the first way.
( { a:10 , b:20 , c:30 } ); has no use as you don't have reference of the object. but same way we can define anonymous function (function(){ })(); which is very useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With