The problem is that you use a function declaration inside an if
block.
From ECMA-262:
NOTE Several widely used implementations of ECMAScript are known to
support the use of FunctionDeclaration as a Statement. However there
are significant and irreconcilable variations among the
implementations in the semantics applied to such
FunctionDeclarations. Because of these irreconcilable differences, the
use of a FunctionDeclaration as a Statement results in code that is
not reliably portable among implementations. It is recommended that
ECMAScript implementations either disallow this usage of
FunctionDeclaration or issue a warning when such a usage is
encountered. Future editions of ECMAScript may define alternative
portable means for declaring functions in a Statement context.
And if you try to use your code in strict mode, you get
SyntaxError: in strict mode code, functions may be declared only at top level or immediately within another function
Instead, you can use
var i='a',
theFunction;
if (i=='a') theFunction = function(){alert('hi');}
else theFunction = function(){alert('bye');};
theFunction();
Or, if your code is simple enough (like example above), use the ternary operator:
var theFunction = i=='a'
? function(){alert('hi');}
: function(){alert('bye');};