使用typeof算法
typeof的運算數未定義,返回的就是 "undefined".
下面定義x為運算數:
有一下5種情況;
運算數為數字 typeof(x) 返回的就是 "number";
字符串 typeof(x) 返回的就是 "string";
布爾值 typeof(x) 返回的就是 "boolean";
對象、數組 、null 時: typeof(x) 返回的就是 "object";
函數 typeof(x) 返回的就是 "function"。
例如:
var x=123456;
alert( typeof(x));//彈出“number”。
</script>
新聞熱點
疑難解答