Friday, August 20, 2021

Difference between functions expression and function declaration in javascript:

 Function expression:

Expression will return a result immediately .

ex:2+3 will return 5.so this is a expression.

similarly , assume a function expression-

<script>
    var calSub = function(x, y){
        return x - y;
    }
 
    console.log("Subtraction : " + calSub(7, 4));
 </script>
here calSub is a function expression.

Function declaration:

A function is a set of statements that performs some task or does some computations and will return the result to the user.

Ex:
function calcAddition(number1, number2) 
    return number1 + number2; 
}





No comments:

Post a Comment

Abstract factory pattern

When single task can be done by multiple groups/family of objects and decision is taken at the runtime.