JavaScript中的复杂数据类型包括typeof运算符。该 typeof运算 操作是一元运算符是其单个操作数之前放置,其可以是任何类型的。它的值是一个字符串,指示操作数的数据类型。
如果typeof运算符的操作数是数字,字符串或布尔值,则其计算结果为“数字”,“字符串”或“布尔值”,并根据计算结果返回true或false。
您可以尝试运行以下代码,以了解如何在JavaScript中使用typeof运算符-
<html> <body> <script> <!-- var a = 10; var b = "String"; var linebreak = "<br />"; result = (typeof b == "string" ? "B is String" : "B is Numeric"); document.write("Result => "); document.write(result); document.write(linebreak); result = (typeof a == "string" ? "A is String" : "A is Numeric"); document.write("Result => "); document.write(result); document.write(linebreak); //--> </script> </body> </html>