📜  if typeof 变量 javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:53.533000             🧑  作者: Mango

代码示例2
// check if a variable is of a certain type
var myVar = "This is a string";

if (typeof myVar === "string") {
    console.log("It's a string!");
} else if (typeof myVar === "number") {
    console.log("It's a number!");
};
// would return "It's a string!" in this case