JavaScriptのtypeofOperatorとは何ですか?
typeof演算子は、単一のオペランドの前に配置される単項演算子であり、任意の型にすることができます。その値は、オペランドのデータ型を示す文字列です。 typeof演算子は、オペランドが数値、文字列、またはブール値の場合、「数値」、「文字列」、または「ブール値」と評価され、評価に基づいてtrueまたはfalseを返します。
| タイプ | typeofによって返される文字列 |
|---|---|
| 数値 | "数値" |
| 文字列 | "文字列" |
| ブール値 | "ブール値" |
| オブジェクト | "オブジェクト" |
| 機能 | "関数" |
| 未定義 | "未定義" |
| Null | "オブジェクト" |
例
<html>
<body>
<script>
var a = 10;
var b = "String";
var linebreak = "<br />";
result = (typeof b == "string" ? "B is String" : "Bis Numeric");
document.write("Result => ");
document.write(result);
document.write(linebreak);
result = (typeof a == "string" ? "A is String" : "Ais Numeric");
document.write("Result => ");
document.write(result);
document.write(linebreak);
</script>
</body>
</html> -
感嘆符「!」とはJavaScriptの演算子?
感嘆符演算子は、式に対して否定を実行します。 例 次のコードを実行して、JavaScriptで感嘆符(!)演算子を実装する方法を学ぶことができます- <html> <head> <title>JavaScript Boolean</title> </head> <body> <script>
-
JavaScriptのビットごとのOR(|)演算子とは何ですか?
ビットの1つが1の場合、ビットごとのOR(|)演算子を使用すると1が返されます。 例 次のコードを実行して、JavaScriptのビットごとのOR演算子の操作方法を学ぶことができます。 <!DOCTYPE html> <html> <body> <script> document.write("Bitwise OR Operator<br>"); &n