> I'll believe things are going in a good direction when `{}.foo` throws an exception in all major JS implementations. But I'm not optimistic about that ever happening.
Okay, please make a little effort to understand meaning rather than taking things completely literally.
Try one of the following:
> ({}).foo
undefined
> var a = {};
undefined
> a.foo
undefined
Now imagine hundreds of lines of code and a bunch of asynchronous callbacks occur between the last two lines, and imagine what that does for your debugging experience. Or watch Wat[1] and see if any of that is what you want your language to do when it happens.
The fact that JavaScript throws an exception on `{ foo: 'bar' }.foo` and not `({}).foo` isn't exactly a defense of the language.
({}).foo returning undefined is exactly what I'd expect. That's a basic part of how accessing properties in Javascript works, and wanting it to work differently is like wanting NullPointerException generation in Java to work differently.
> Now imagine hundreds of lines of code and a bunch of asynchronous callbacks occur between the last two lines, and imagine what that does for your debugging experience
That's what using typed signatures for your objects is for. It's not even substantially different from having, say, Java with an object with properties that can be nullable or Optional.empty().
...and get warnings later when you attempt to access anything that's not propertyA, propertyB, or a JS builtin, as well as warnings if you attempt to use either without verifying whether it's undefined or not, as well as warnings if you then try to use them in places restricted to non-matching types.
With Typescript, you can turn on full strictness and make these build-rejecting compile-time errors, too.
Try one of the following:
Now imagine hundreds of lines of code and a bunch of asynchronous callbacks occur between the last two lines, and imagine what that does for your debugging experience. Or watch Wat[1] and see if any of that is what you want your language to do when it happens.The fact that JavaScript throws an exception on `{ foo: 'bar' }.foo` and not `({}).foo` isn't exactly a defense of the language.
[1] https://www.destroyallsoftware.com/talks/wat