Variables and Optional Types in Dart
Update : Reworked some of the optional types section based on comments. Intro Dart is a structured web programming language, complete with libraries, a virtual machine, and an editor. Dart is designed to help developers create more complex and feature rich apps for the modern web. In this post, we look at variables and their types in Dart. Variables The most simple example declares a variable without an explicit type: main() { var msg = 'hello'; print(msg); } > hello The most common way to declare a variable is to use the var keyword. This is truly a variable, as shown here: main() { var msg = 'hello'; msg = 'world'; print(msg); } > world final So far, this is a lot like JavaScript. Let's see what Dart can do differently. Dart allows you to mark variables as final . main() { final msg = 'hello'; msg = 'world'; // ERROR: cannot assign value to final variable print(msg); } This all looks sim