In the below program, the function will return a string indicating that that object is not a number using TypeScript nullish coalescing which will provide a default value for that variable if it is either null or undefined.
function num(obj : any) : number { return obj?? "Not a number" } console.log(num(undefined)) /* Not a number */ console.log(num(3)) /* 3 */
The ?? is nullish coalescing operator which will provide the default value on the left hand side of that operator.