D
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

AspectKeywordBehavior
varType inferred at compile timeFully type-safe after inference
dynamicType checking disabledNo compile-time checks, runtime errors possible
ObjectBase class, non-nullableMust cast to use specific methods
Object?Nullable root typeSame 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