Js is a dynamic language. The first line is not “wrong”, it just isn’t what you want. It does indeed just add a new field in the gridContainer object. Tthis is perfectly valid javascript.
Js doesn’t “know” that it is running in a browser, nor does it care. It doesn’t know what the appropriate value or type is for these fields in a ‘div’ or anything else.
Yes, you pretty much have to use trial and error, unless there exists some other tool that can typecheck your code. I don’t do webdev, so I'm not sure.