We can write functions in 2 ways:
var v1 = m1('hello'); // error
var v2 = m2('hello'); // OK
var m1 = function(param){
// ...
return param;
}
function m2(param){
// ...
return param;
}
var v1 = m1('hello'); // OK
var v2 = m2('hello'); // OK
As I know there is only one difference - time of creation:
m2
in compilation time, so we can use it 'before' declaration - like in my case.
m1
in assignment time (code goes line by line) and we cannot use it before.
Is one more efficient for memory or performance?
In which case is one way more semantic, in which case second?
Is here next difference?
When we should use first and when second one?
.
// edit really primitive perf test - same results
// http://jsperf.com/performance-function-writing-way