Skip to content Skip to sidebar Skip to footer

What's The Difference Between Function And => In Typescript?

Currently, I am learning TypeScript. I am quite confused about the difference between keyword function and => (fat arrow). Please see the code below: interface Counter { (st

Solution 1:

fat arrow functions have a shorter syntax compared to function expressions and lexically bind the this value. Arrow functions are always anonymous and effectively turn function (arguments) { return expression; } into (arguments) => expression. If using an expression after an arrow, the return is implicit, so no return is required.

Solution 2:

It's all about keeping the context/scope in JavaScript. Take a look here: What is this in JavaScript and Typescript.

Post a Comment for "What's The Difference Between Function And => In Typescript?"