JavaScript の比較と論理演算子
比較演算子
演算子説明例演算結果
== 2 == 3 SEに等しい
=== 常に等しい(値と型の両方を実行する必要がありますCompare) (2 === 2 TRUE) (2 === "2" FALSE )
!= 等しくありません。<> 2 == 3 TRUE
> と書くこともできます。 ; 3 FALSE
<2 < 3 TRUE
>= 2 以上 >= 3 FALSE
<= 2 <= 3 TRUE
are は文字列比較にも使用できます。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<script type="text/javascript">
var a=5,b="5";
document.write(a==b);
document.write("<br />");
document.write(a===b);
document.write("<br />");
document.write(a!=b);
document.write("<br />");
document.write(a!==b);
</script>
</head>
<body>
</body>
</html>論理演算子
演算子説明例演算結果
&& 論理 AND (および) x = 2; y = 6 X && y & gt; 偽
|| y = 2; y & gt; y
;
条件演算子
JavaScript には、特定の条件に基づいて変数に値を割り当てる条件演算子も含まれています。
構文
変数名=(条件)?値1:値2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<script type="text/javascript">
var a=5,b="5";
document.write(a&&b > 10);
document.write("<br />");
document.write(a||b <6);
document.write("<br />");
document.write(!(a>b));
</script>
</head>
<body>
</body>
</html>
新しいファイル
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>php中文网(php.cn)</title>
<script type="text/javascript">
var a=5,b="5";
document.write(a==b);
document.write("<br />");
document.write(a===b);
document.write("<br />");
document.write(a!=b);
document.write("<br />");
document.write(a!==b);
</script>
</head>
<body>
</body>
</html>
プレビュー
Clear
- おすすめコース
- コースウェアのダウンロード
現時点ではコースウェアはダウンロードできません。現在スタッフが整理中です。今後もこのコースにもっと注目してください〜
このコースを視聴した生徒はこちらも学んでいます
















