Saturday, 15 September 2012

javascript: overriding (not just defining) a function in if statement -



javascript: overriding (not just defining) a function in if statement -

i have next javascript.

var f = function() { ... }; if (x === 1) { // redefine f. f = function() { ... }; }

is code valid ? in other words can redefine javascript function within if statement write code.

i worried because of this: function declarations within if/else statements?

yes can that.

f = function() { ... };

is not function declaration, function expression (assigned f), problems mentioned in other question don't apply here.

only variable , function declarations hoisted.

javascript

No comments:

Post a Comment