Created with <3 with dartpad.dev.
Last active
March 21, 2023 04:03
-
-
Save topex-psy/245f9eff5f004b4cad1c52308cbfc46e to your computer and use it in GitHub Desktop.
Dart 2. Constant & Nullable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void main() { | |
var nama = "Taufik"; | |
const umur = 20; | |
final double? tinggi; | |
bool? isMarried; | |
bool isHasJob = true; | |
final jobs = <String>["Programmer", "Web Developer", "Software Engineer"]; | |
// tidak bisa karena constant | |
// umur = 25; | |
// tidak bisa karena variabel string | |
// nama = 100; | |
tinggi = 170.0; | |
isMarried = false; | |
// tidak bisa karena tidak nullable | |
// isHasJob = null; | |
// merubah isi list (final) | |
jobs.clear(); | |
jobs.addAll(["Arcitect", "Carpenter"]); | |
print("Nama\t: $nama"); | |
print("Umur\t: $umur"); | |
print("Tinggi\t: ${tinggi.toStringAsFixed(1)} cm"); | |
print("Sudah menikah\t: ${isMarried ? "Sudah" : "Belum"}"); | |
print("Sudah bekerja\t: ${isHasJob ? "Sudah" : "Belum"}"); | |
print("Pekerjaan:\n${jobs.join(", ")}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment