¡GoConqr estrena diseño! Cuéntanos qué te parece.

Apuntes

Expression vs Declaration

Ram Sham Javascript Inglés 1 página

Contenido del apunte (1)

Página 1

If an expression starts with the keyword function, it is a function expression.

var dayName = function() { var names = ["Sunday", "Monday", "Tuesday", "Wednesday",

"Thursday", "Friday", "Saturday"];

return function(number) {

return names[number];

};

}();

However, if a statement starts with function, it is a function declaration,

var names = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];

function dayName(number) {

return names[number];

}

which requires a name and, not being an expression, cannot be called by writing parentheses after it.

You can think of the extra wrapping parentheses as a trick to force the function to be interpreted as an expression.

Información

Descripción
(Functions) Javascript Apunte sobre Expression vs Declaration, creado por Ram Sham el 06/01/2017.
Creado por
Ram Sham
Visitas
0
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?