Internet Explorer Javascript Strangeness 
Friday, March 11, 2011, 12:24 AM - Web
I finally solved one of the issues my Pic a Day gallery had with Internet Explorer:
For any reason, IE (tryed on IE6, IE7, IE8) is unable to dynamically create a not yet declared variable when you directly affect the result of some function.

Javascript is supposed to automatically create global scope variable if you affect something into an undeclared variable:

foo = 5;

...will instanciate the global "foo" variable if not yet declared.
However, if you assign the result of some functions to an unexisting variable, IE simply fails and stops evaluating the funtion where the issue occurs:

foo = document.getElementById('bar');

Assuming there is a element called 'bar', then this line fails if 'foo' is not yet declared (but this works as expected under Firefox 3.x). Declaring 'foo' before using it solves this Internet Explorer issue:

var foo;
foo = document.getElementById('bar');


Comments 
Comments are not available for this entry.