2 replaced http://stackoverflow.com/ with https://stackoverflow.com/
source | link

Your first example is an expression while the second example is a statement. Defining functions as expressions allows for more flexibility in where the definition can occur, what you can assign it to, that you can pass it as a parameter, etc...

For example:

SomeThing('abc', function(a,b) {return a*b;});

vs...

function tmp(a,b) { 
    return a*b;
}

SomeThing('abc', tmp);

More complex examples would become obcenely complicated without the function expression syntax.

Look at http://stackoverflow.com/questions/111102/how-do-javascript-closures-workhttps://stackoverflow.com/questions/111102/how-do-javascript-closures-work

Your first example is an expression while the second example is a statement. Defining functions as expressions allows for more flexibility in where the definition can occur, what you can assign it to, that you can pass it as a parameter, etc...

For example:

SomeThing('abc', function(a,b) {return a*b;});

vs...

function tmp(a,b) { 
    return a*b;
}

SomeThing('abc', tmp);

More complex examples would become obcenely complicated without the function expression syntax.

Look at http://stackoverflow.com/questions/111102/how-do-javascript-closures-work

Your first example is an expression while the second example is a statement. Defining functions as expressions allows for more flexibility in where the definition can occur, what you can assign it to, that you can pass it as a parameter, etc...

For example:

SomeThing('abc', function(a,b) {return a*b;});

vs...

function tmp(a,b) { 
    return a*b;
}

SomeThing('abc', tmp);

More complex examples would become obcenely complicated without the function expression syntax.

Look at https://stackoverflow.com/questions/111102/how-do-javascript-closures-work

1
source | link

Your first example is an expression while the second example is a statement. Defining functions as expressions allows for more flexibility in where the definition can occur, what you can assign it to, that you can pass it as a parameter, etc...

For example:

SomeThing('abc', function(a,b) {return a*b;});

vs...

function tmp(a,b) { 
    return a*b;
}

SomeThing('abc', tmp);

More complex examples would become obcenely complicated without the function expression syntax.

Look at http://stackoverflow.com/questions/111102/how-do-javascript-closures-work