So what does the notation var params = {}; mean ? What is created ?
{}
creates a new, empty object. This is called an "object initialiser" (aka "object literal"). Then the object is assigned to the variable params
, and the code follows on by adding a couple of properties to the object.
It could also have added the properties as part of the initialiser:
var params = {
quality: "high",
allowscriptaccess: "sameDomain"
};
You can also write {}
as new Object()
(provided the symbol Object
hasn't been shadowed), but it's best practice to use {}
(because Object
can be shadowed).
MDN has a page on working with objects. Oddly, that page primarily uses new Object()
rather than {}
.