Dart LanguageBeginner10 XP2 min read
What is the difference between var, dynamic, and Object in Dart?
TL;DR: var uses type inference (becomes the inferred type); dynamic opts out of type checking entirely; Object is the base class of all non-null Dart types and still provides type safety.
Full Answer
| Aspect | Keyword | Behavior |
|---|---|---|
| var | Type inferred at compile time | Fully type-safe after inference |
| dynamic | Type checking disabled | No compile-time checks, runtime errors possible |
| Object | Base class, non-nullable | Must cast to use specific methods |
| Object? | Nullable root type | Same as dynamic but with null checks |
🚫
Avoid dynamic. It disables Dart's type system entirely for that variable. Use Object + type narrowing, generics, or sealed classes instead.
Interview Tip
💡
The Dart style guide says: use var for local variables where the type is obvious from context; use explicit types for public APIs; never use dynamic unless you're writing a plugin or working with truly unknown JSON data.
#var#dynamic#object#type-inference#type-safety