如何在 JavaScript 中对带有参数的 typeof 使用?
参数对象是要传递给函数的参数。它是所有函数可访问的一个变量。假设有两个参数传递给一个函数,那么你可以按以下方式访问它们
arguments[0] arguments[1]
同样,在 JavaScript 中,你可以使用 typeof 带有参数的方式。首先,让我们看看如何使用 typeof。typeof 运算符是一个放在其单个操作数之前的单目运算符,操作数的类型可以是任何类型。
示例
以下代码演示了如何实现 typeof 运算符
<html>
<body>
<script>
var a = 20;
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>现在让我们看看如何在 JavaScript 中将 typeof 与参数一起使用。typeof 参数将返回如下对象
document.write(typeof arguments);
假设你有两个参数,那么你可以使用 typeof 之类的引用它们,它将返回 typeof 参数。
document.write(typeof arguments[0]); document.write(typeof arguments[1]);
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP