In Dart, everything is an object, including variables, numbers, functions, and so on
int a = 11; print(a==11); // true a = null; print(a==null); // trueCopy the code
Num, int and double
  • Dart does not have floating-point types. Int and double are the faces of dart, and num is a variable that contains both int and double.
  • In Java, 5/2=2, but in DART, 5/2=2.5. Dart has a special symbol, “~/”, which means to divide and round, just like in Java, so 5 ~/ 2=2.
  • In Java, int a, then a=0; In DART, int a, then a=null.
  • Long in Java corresponds to int in DART
Ternary operator? :
  • Available in DART? The: operator, as in:
int a=1; int b = a>1? 3:4;Copy the code
  • But there’s also…? Operators such as:
int a ; int b = a ?? 2; // if a is empty, return 2 a?? = 2; // assigns 2 to a if a is emptyCopy the code
int a; print('a=$a'); // a = null int b = a ?? 2; print('b=$b'); // b = 2 a ?? = 3; print('a=$a'); // a = 3Copy the code
In Dart, only Boolean values are true and false, and nothing else is valid (unlike JS).

Assert (bool) statement, easy to use

If bool==true is normal and then executed otherwise an exception is thrown.

int a = 1; int b = 2; assert(a>b); / / thrown exceptionCopy the code
Scope of a variable

In Dart, there are no Java keywords that declare variable scopes, such as public, protected, and private. If an identifier begins with an underscore _, it is private, otherwise it is public.

Dart is a strongly typed language
  • Variables can be declared using an explicit type such as int String, and can only be assigned to data of that type.
  • The first time a variable is assigned, Dart automatically deduces its type based on the assigned data. For example, var age = 1 indicates that age is an int and cannot be assigned to another type, such as age = “12”.
Difference between Dynamic and Object
  • In Dart, everything is an Object, and every Object must have a class. All classes (excluding Object itself) directly or indirectly extend Object. If a class does not explicitly extend a class, it extends Object by default. Object represents a type. All other classes are descendants of Object, so you can use Object to receive objects of any type. Dart does a type check at compile time. Dart is a strongly typed language, which is a static language feature. However, the parameters received with Object can only call the attributes and functions in Object. If the parameters exceed the scope of Object, an error will be reported. The type can be directly checked during compilation.
  • Dart wants to do both dynamic and static languages as much as possible. So dynamic allows the compiler to do no type checking when you declare a variable using Dynamic. So you can use Dynamic to take any type of argument and call the method you want, and the compiler doesn’t check, and if it does call a method that doesn’t exist, it calls the noSuchMethod method of Dynamic.
Type promotion is available in Java, but not in DART.
  • In Java, strings and numbers are added to link strings. Dart does not allow strings to add numbers, such as converting numbers to strings, which is string chaining.