⚠️ This lesson is retired and might contain outdated information.

Understand Variables and Constants in Dart

Jermaine Oppong
InstructorJermaine Oppong
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 2 years ago

In this lesson, we will look at how to create variables and constants. These are containers that store data for later reference and/or retrieval.

Dart is an object-oriented programming language by Google, which aims to help the developer build modern web applications. It covers client, server and now mobile with Flutter. It comes with a range of tools including a virtual machine, core libraries, and package management repository, lending enough ammunition to start your next project.

Learn more at https://dartlang.org

Instructor: [00:00] Here is an example of a variable. Dart is able to infer the type of value assigned to our variable, which in this case is an integer, although we could be explicit by declaring the type.

[00:16] We can also set constant values, which essentially are values that cannot be changed once they are set. This comes in two forms. There's the final keyword. If we attempt to reset this to a different value, we will get an error.

[00:36] The second form of declaring constant values is using the const keyword. The difference in practice between const and final is you use final when certain instance variables belong into classes.

[00:49] Also, const is treated as a compile term constant, which means that any value we assign will be calculated during code compilation. Const variables must therefore be initialized with a valid const value, or an exception is thrown.

[01:10] Some of the valid const values are number, string, Boolean, array, map, symbol, and any constructors marked as const.

egghead
egghead
~ just now

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today