In your example, a semicolon is not needed. Or, indeed, expected; the interpreter will ignore it.
But if you have to do this:
var test = function() { return; };
... expected semicolon . Because you enter a semicolon, it is not needed (your interpreter will "fix" it if you do not leave it), but it generally recommended that you use it anyway.
The difference is that function name() {} is a compound statement, whereas var name = function() {}; is a simple ad.
Link: http://javascript.crockford.com/code.html
source share