I'm an experienced C++/Java programmer working in Javascript for the first time. I'm using Chrome as the browser.
I've created several Javascript classes with fields and methods. When I read an object's field that doesn't exist (due to a typo on my part), the Javascript runtime doesn't throw an error or exception. Apparently such read fields are 'undefined'. For example:
var foo = new Foo();
foo.bar = 1;
var baz = foo.Bar; // baz is now undefined
I know that I can check for equality against 'undefined' as mentioned in "Detecting an undefined object property in JavaScript", but that seems tedious since I read from object fields often in my code.
Is there any way to force an error or exception to be thrown when I read an undefined property?
And why is an exception thrown when I read an undefined variable (as opposed to undefined object property)?