Friday, September 13, 2013

JavaScript - Calling function "statements" before definition

function statements get interpreted and will be added to the execution stack before code execution then that's the reason but have attention that it doesn't happen to neither function expressions nor functions which define by Function constructor.

<!DOCTYPE html><html lang="en"><body><script> // logs 11 console.log(aFunc(1, 2, 3)); function aFunc(x, y, z) { return x*y + arguments[0]*arguments[1]*arguments[2] };
// logs "Uncaught TypeError: ..." console.log(iFunc(1, 2, 3)); var iFunc = function (x, y, z) { return x*y + arguments[0]*arguments[1]*arguments[2] };
// logs "Uncaught TypeError: Property 'bFunc' of object [object Object] is not a function" console.log(bFunc(1, 2, 3)) var bFunc = function (x, y, z) { return x*y + arguments[0]*arguments[1]*arguments[2] }; </script></body></html>

Share/Bookmark

No comments: