大なり演算子 (>
) は、左辺のオペランドが右辺のオペランドより大きい場合は true
を返し、それ以外の場合は false
を返します。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
構文
x > y
解説
例
文字列と文字列の比較
console.log("a" > "b"); // false
console.log("a" > "a"); // false
console.log("a" > "3"); // true
文字列と数値の比較
console.log("5" > 3); // true
console.log("3" > 3); // false
console.log("3" > 5); // false
console.log("hello" > 5); // false
console.log(5 > "hello"); // false
console.log("5" > 3n); // true
console.log("3" > 5n); // false
数値と数値の比較
console.log(5 > 3); // true
console.log(3 > 3); // false
console.log(3 > 5); // false
数値と BigInt の比較
console.log(5n > 3); // true
console.log(3 > 5n); // false
ブール値、 null 、 undefined 、 NaN の比較
console.log(true > false); // true
console.log(false > true); // false
console.log(true > 0); // true
console.log(true > 1); // false
console.log(null > 0); // false
console.log(1 > null); // true
console.log(undefined > 3); // false
console.log(3 > undefined); // false
console.log(3 > NaN); // false
console.log(NaN > 3); // false
仕様
ブラウザーの互換性
BCD tables only load in the browser