Force JavaScript exception/error when reading an undefined object property? <p>I'm an experienced C++/Java programmer working in Javascript for the first time. I'm using Chrome as the browser.</p> <p>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:</p> <pre><code>var foo = new Foo(); foo.bar = 1; var baz = foo.Bar; // baz is now undefined </code></pre> <p>I know that I can check for equality against 'undefined' as mentioned in "<a href="http://stackoverflow.com/questions/27509/detecting-an-undefined-object-property-in-javascript">Detecting an undefined object property in JavaScript</a>", but that seems tedious since I read from object fields often in my code.</p> <p><strong>Is there any way to force an error or exception to be thrown when I read an undefined property?</strong></p> <p>And why is an exception thrown when I read an undefined variable (as opposed to undefined object property)?</p>