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

Fluent interface pattern

 public class UserConfigurationManager {     private String userName;     private String password;     private UserConfigurationManager() { ...