Difference between Normal function and arrow function

FatimaAlam1234 - Dec 1 '23 - - Dev Community

Normal Function

function multiply(num1, num2) {
const result = num1 * num2
return result
}

Arrow function

this keyword->

const obj = {
name: 'deeecode',
age: 200,
print: function() {
console.log(this)
}
print2: () =>{
console.log(this)
}
}

obj.print();
obj.print2();

Output ->
{name: 'deeecode', age: 200, print: ƒ}
{Window Global object}

i.e. this for Arrow function is always a window's scope and so it takes the window global object.

arguments keyword only exists in the normal function and not the arrow one bcoz when we add ay extra arguments while calling in case of arrow function it throw an error whereas it behaves fie with normal function.

Image description

call, apply(), bind() doesn't have any effect on arrow functions.
Arrow function always picks up the window scope for this keyword

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .