viernes, 16 de noviembre de 2012

Function Declarations vs. Function Expressions

A Function Declaration is:
function add(numberOne, numberTwo){
    return numberOne + numberTwo;
}
A Function Expressions is:
var add = function(numberOne, numberTwo){
      return numberOne + numberTow;
};
When we write a function declaration, it's loaded in the execution context, before the script runs, but when we write a function expresion, the interpreter, load while it's executing the code. So we can find a simple error.
//alert(add(10,10)); the vm doesn't found the function add(), because it's not loaded
var add = function(numberOne, numberTwo){
      return numberOne + numberTow;
};

No hay comentarios:

Publicar un comentario