İki funksiya göstəriləcək say olub-olmadığını müəyyən edir. Hər ikisi --strict rejimində tip yoxlamasından keçir. Konsola nə çıxacaq?
function withTruthiness(count: number | undefined): string {
if (count) return `${count} new`;
return "no data";
}
function withUndefinedCheck(count: number | undefined): string {
if (count !== undefined) return `${count} new`;
return "no data";
}
console.log(withTruthiness(3));
console.log(withTruthiness(0));
console.log(withUndefinedCheck(0));
console.log(withUndefinedCheck(undefined));
console.log(withTruthiness(NaN));