function expression and function declaration 1

function expression and function declaration

// Function Declaration
function add(a, b) {
	return a + b;
}
console.log(add(1,2)); //3

// Function Expression
const add = function (a, b) {
	return a + b;
};

console.log(add(1,2)); //3

Here is what the above code is Doing:
1. We declare a function called add.
2. We call the function add and pass in the arguments 1 and 2.
3. The function add returns the sum of 1 and 2.
4. We log the result to the console.

The function declaration is hoisted to the top of the file.
The function expression is not hoisted to the top of the file.

Similar Posts