Important concepts

As you learn about the Dart language, keep these facts and concepts inmind:

  • Everything you can place in a variable is an object, and everyobject is an instance of a class. Even numbers, functions, andnull are objects. All objects inherit from the Object class.

  • Although Dart is strongly typed, type annotations are optionalbecause Dart can infer types. In the code above, numberis inferred to be of type int. When you want to explicitly saythat no type is expected,use the special type dynamic.

  • Dart supports generic types, like List<int> (a list of integers)or List<dynamic> (a list of objects of any type).

  • Dart supports top-level functions (such as main()), as well asfunctions tied to a class or object (static and instancemethods, respectively). You can also create functions withinfunctions (nested or local functions).

  • Similarly, Dart supports top-level variables, as well as variablestied to a class or object (static and instance variables). Instancevariables are sometimes known as fields or properties.

  • Unlike Java, Dart doesn’t have the keywords public, protected,and private. If an identifier starts with an underscore (_), it’sprivate to its library. For details, seeLibraries and visibility.

  • Identifiers can start with a letter or underscore (_), followed by anycombination of those characters plus digits.

  • Dart has both expressions (which have runtime values) andstatements (which don’t).For example, the conditional expressioncondition ? expr1 : expr2 has a value of expr1 or expr2.Compare that to an if-else statement, which has no value.A statement often contains one or more expressions,but an expression can’t directly contain a statement.

  • Dart tools can report two kinds of problems: warnings and errors.Warnings are just indications that your code might not work, butthey don’t prevent your program from executing. Errors can be eithercompile-time or run-time. A compile-time error prevents the codefrom executing at all; a run-time error results in anexception being raised while the code executes.