Empty objects in javascript

What is the purpose of creating an empty object? For example this code has an empty object baz why? I dont understand the purpose of creating an empty object Im sure its simple concept. Thanks

var object = {
foo: 1,
“bar”: “some string”,
baz: {

1 Like

You typically create an empty object, when you plan to add property/value pairs at a later point in the program. You need the object to be created first (hence the empty object) before you can add properties/values to it.


True, I agree with what Randy is saying. Some people may choose to make it null instead, but the your code would need to know how to handle that. Both are valid approaches.