如何在 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