Will JavaScript evaluate a property's value if it's not part of an assignment statement?

Posted by Bungle on Stack Overflow See other posts from Stack Overflow or by Bungle
Published on 2010-06-09T18:42:09Z Indexed on 2010/06/09 19:02 UTC
Read the original article Hit count: 321

I've come across a fairly obscure problem having to do with measuring a document's height before the styling has been applied by the browser. More information here:

In Dave Hyatt's comment from June 27, he advises simply checking the document.body.offsetLeft property to force Safari to do a reflow.

Can I simply use the following statement:

document.body.offsetLeft;

or do I need to assign it to a variable, e.g.:

var force_layout = document.body.offsetLeft;

in order for browsers to calculate that value?

I think this comes down to a more fundamental question - that is, without being part of an assignment statement, will JavaScript still evaluate a property's value? Does this depend on whether a particular browser's JavaScript engine optimizes the code?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about browser