Variables

Here’s an example of creating a variable and initializing it:

  1. var name = 'Bob';

Variables store references. The variable called name contains areference to a String object with a value of “Bob”.

The type of the name variable is inferred to be String,but you can change that type by specifying it.If an object isn’t restricted to a single type,specify the Object or dynamic type, followingdesign guidelines.

  1. dynamic name = 'Bob';

Another option is to explicitly declare the type that would be inferred:

  1. String name = 'Bob';

Note: This page follows the style guide recommendation of using var, rather than type annotations, for local variables.