GoConqr has a new look! Let us know what you think.

Notes

Expression vs Declaration

Ram Sham Javascript English 1 page

Content of the notes (1)

Page 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.

Information

Description
Javascript (Functions) Note on Expression vs Declaration, created by Ram Sham on 06/01/2017.
Created by
Ram Sham
Views
0
Rating

Feedback

What is it about?

What do you think of the new look?

How do you like it?