-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvar_type_exp.dart
33 lines (29 loc) · 976 Bytes
/
var_type_exp.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void main() {
// local variable
int num1 = 2;
double num2 = 3.0;
bool isTrue = true;
// to check data type
print( num1 + num2);
print((num1 + num2) is int);
print((num1 + num2).runtimeType);
// var keyword
// `var` is like you set up a `dynamic type` variable
// => "until you assign value"
var lname; // dynamic since no data assign
var fname = 'worajedt'; // string
lname = 'test';
lname = 25; // na ni ?
// so, be careful to use `var`
final String fullname = 'Worajedt S.';
// fullname = 'Jedt S.'; // why?
// `final` keyword make variable CANNOT be re-assigned
// it's a good practice
const int age = 47;
print(age.isEven); // is ok since you read const data
const bool isIt = age.isEven; // why?
// `const` keyword almost like `final` but...
// it create immutable compile-time constant
// faster than final sometime, but it will have to
// assign value BEFORE compile, NOT and expression
}