D
Dart LanguageBeginner10 XP1 min read

What is the fat arrow (=>) syntax in Dart and when should you use it?

TL;DR: The fat arrow => is syntactic sugar for a single-expression function body: int add(int a, int b) => a + b; is equivalent to int add(int a, int b) { return a + b; }

Full Answer

Use => when a function body is a single expression. It improves readability, especially for getters, short callbacks, and widget build methods.

Code Examples

dartFat arrow usage
Output
add(2, 3) returns 5
greeting returns 'Hello, name!'

Interview Tip

💡

Dart style guide recommends => for simple getters and single-expression methods. Avoid it when the expression is complex — readability matters more than brevity.

#fat-arrow#arrow-function#syntax#expression-body