不等価 (!=)
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
不等価演算子 (!=
) は、2 つのオペランドが等しくないことを検査し、論理値で結果を返します。厳密不等価演算子とは異なり、異なる型のオペランドを変換して比較を行おうとします。
試してみましょう
console.log(1 != 1);
// Expected output: false
console.log("hello" != "hello");
// Expected output: false
console.log("1" != 1);
// Expected output: false
console.log(0 != false);
// Expected output: false
構文
js
x != y;
解説
例
型変換がない場合の比較
js
1 != 2; // true
"hello" != "hola"; // true
1 != 1; // false
"hello" != "hello"; // false
型変換がある場合の比較
js
"1" != 1; // false
1 != "1"; // false
0 != false; // false
0 != null; // true
0 != undefined; // true
0 != !!null; // false (論理 NOT 演算子を参照)
0 != !!undefined; // false (論理 NOT 演算子を参照)
null != undefined; // false
const number1 = new Number(3);
const number2 = new Number(3);
number1 != 3; // false
number1 != number2; // true
オブジェクトの比較
js
const object1 = { key: "value" };
const object2 = { key: "value" };
object1 != object2; // true
object2 != object2; // false
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-equality-operators |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Inequality ( a != b ) |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.