← TypeScript5 / 43
null, undefined, dan strictNullChecks
Dengan opsi strictNullChecks: true, TypeScript mencegah error fatal Cannot read property of undefined saat runtime.
👀 Contoh dulu
let email: string | null = null; email = "bimo@test.com"; console.log(email);
Hasilnya: bimo@test.com
💡 strictNullChecks wajib diaktifkan di setiap proyek profesional.
📝 Sekarang giliranmu
Deklarasikan variabel token yang boleh menampung tipe string atau null, lalu inisialisasi awal dengan nilai null.
Preview