Handling Optional Properties In TypeScript With The Elvis Operator
[!INFO]-
topic: π¦ TypeScript
links: Interfaces in TypeScript
source: TypeScript course by the native web
tags: #permanent-noteΒ #published
Last Modified:
=dateformat(this.file.mtime, "MMM. dd, yyyy - HH:mm")
When handling optional parameters in TypeScript, you have to handle cases, where this parameter is not set. You can do this with the Elvis operator ?.
console.log(donuldDuck.middleName?.toLocaleUpperCase());
The code to the right of the ?
is only executed, if the property before it is defined.