Snippet:
function sampleFunction(sample:string|number|string[])
{
if(typeof sample == "string")
{
console.log("Sample is String " + sample);
}
else if(typeof sample == "number")
{
console.log("Sample is Number " + sample);
}
else{
console.log("Sample is String Array " + sample);
}
}
var sample:number; //Assigning the variable as a number
sampleFunction(sample);
Console Output:
Sample is String Array undefined
Even though the var type is specified as "number", why does the output show "String array"?