25
When running the following block of code, FF and Chrome output typeof(hiya) = string while IE7/8 output typeof(hiya) = undefined.
<html>
<body>
<script type="text/javascript">
window.hiya = 'hiya';
</script>
<script type="text/javascript">
if( false ) {
var hiya = 1;
}
document.write( "typeof(hiya) = "+ typeof(hiya) );
</script>
</body>
</html>
Each of the following makes the problem go away:
- Combining everything into a single
<script>block. - Removing the
ifblock. - Renaming
var hiya = 1tovar hiya2 = 1. - Renaming
var hiya = 1towindow.hiya = 1. - Renaming
var hiya = 1tohiya = 1.
What is happening? Is there a scoping bug in IE?