This commit is contained in:
Vishakha Tak 2024-11-23 20:08:41 +05:30 committed by GitHub
commit 1ba369501a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,6 +37,11 @@ let notSure: any = 4;
notSure = "maybe a string instead";
notSure = false; // okay, definitely a boolean
// When we are not sure about the type, and don't want to use "any", we can use "unknown" type
let unknownVariable: unknown = 'Some string'; // we don't fully know yet the type
unknownVariable = 2; // possible
const someVariable: string = unknownVariable; // Invalid; we can't assign unknownVariable to any other type (without an explicit assertion), unlike any
// Use const keyword for constants
const numLivesForCat = 9;
numLivesForCat = 1; // Error