Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

typescript default value if null

/* Use || operator to assign a default value whence the first variable
evaluates to a 'falsy' value
	- Example with strings (you can replace string with any type T) */

let x: string | null = null;
let y: string = x || "My default value"
 
PREVIOUS NEXT
Tagged: #typescript #default #null
ADD COMMENT
Topic
Name
4+4 =