Javascript function definition error -


this question has answer here:

var add = function addnums(a,b) {     return a+b; } alert("sum " + addnums(10,20)); 

why can't use addnums directly in above javascript ?

ps : know other alternatives, question why above specified method doesn't work.

you can.

var add = function addnums(a,b) {     return a+b; } alert("sum " + (function(a,b) { return a+b; })(10,20) ); 

plus may shorten syntax:

var addnums = function(a,b) { ... } 

or

function addnums(a,b) { ... } 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -