Notizen
Expression vs Declaration
Inhalt der Notizen (1)
Seite 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.
Informationen
- Beschreibung
- Javascript (Functions) Notiz am Expression vs Declaration, erstellt von Ram Sham am 06/01/2017.
- Erstellt von
- Ram Sham
- Aufrufe
- 0
- Bewertung