The following statement if (false) { function myFunction(){ return "I work!"; } } should declare a variable, "myFunction," in the parent namespace, if it doesn't already exist, but it should neither assign a value to the variable nor create a function. This behavior is confirmed, for example, in the Google Chrome console: > if(false){function myFunction(){return "I work!";}} < undefined > "myFunction" in window < true > typeof myFunction < "undefined" And attempting to invoke myFunction throws a TypeError error. In the Safari console, however, a working function is created and assigned to the variable: > if(false){function myFunction(){return "I work!";}} < undefined > "myFunction" in window < true > typeof myFunction < "function" > myFunction() < "I work!" The behavior is the same if the variable already exists and has a value in the parent namespace: > myFunction = "just a string" < "just a string" > typeof myFunction < "string" > if(false){function myFunction(){return "I work!";}} < undefined > typeof myFunction < "function" Thus, the existing value is overwritten with the function.
<rdar://problem/55361190>