Try: if(true) { function test() { alert("SUCCESS!"); } } else { function test() { alert("FAIL!"); } } test(); // alerts "FAIL!" Not sure if I listed the correct webkit version, this bug happens for me in Windows Safari 4.0.4 (531.21.10) I suspect all function declarations are evaluated ignoring the if/else clause. Bug mitigation, declare functions as variables... if(true) { var test = function() { alert("SUCCESS!"); } } else { var test = function() { alert("FAIL!"); } } test(); // alerts "SUCCESS!"
Appologies, learned the difference between declarations and expressions. This is exactly according to ECMA 262 spec and is a developer error.