I'm learning Javascript and am told setting a variable equal to a function is done all the time. I'm trying to figure out why. Below is sample code that suggests there is no advantage. What am I missing?
<script type="text/javascript">
var addVar = function() {
var myTemp = 0;
for(i=0; i< arguments.length;i++){
myTemp+=arguments[i];
}
return myTemp;
}
function addFunc() {
var myTemp = 0;
for(i=0; i< arguments.length;i++){
myTemp+=arguments[i];
}
return myTemp;
}
function addTwo(first,second){
return first+second;
}
alert( addTwo(addVar(1,2,3),addVar(1,2,3)) );
alert( addTwo(addFunc(1,2,3),addFunc(1,2,3)) );
</script>