Code:
function fun(example:string|number|string[])
{
if(typeof example == "string")
{
console.log("Example is String " + example);
}
else if(typeof example == "number")
{
console.log("Example is Number " + example);
}
else{
console.log("Example is String Array " + example);
}
}
var example:number; //Here i have assigned the var as a number
fun(example);
Output:
Example is String Array undefined
I have given the var type as a "number", but why the output screen shows "String array"?
undefinedgets assigned automatically if you dont assign it on your own