JavaScript Math.max()
ตัวอย่าง
let x = Math.max(5, 10);
ความหมายและการใช้งาน
Math.max() วิธีการส่งกลับตัวเลขที่มีค่าสูงสุด
เคล็ดลับ: Math.min()ส่งกลับตัวเลขที่มีค่าต่ำสุด
ตัวอย่างเพิ่มเติม
let a = Math.max(5, 10);
let b = Math.max(0, 150, 30, 20, 38);
let c = Math.max(-5, 10);
let d = Math.max(-5, -10);
let e = Math.max(1.5, 2.5);
รองรับเบราว์เซอร์
Math.max()
เป็นคุณลักษณะ ECMAScript1 (ES1)
ES1 (JavaScript 1997) ได้รับการสนับสนุนอย่างสมบูรณ์ในเบราว์เซอร์ทั้งหมด:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
ไวยากรณ์
Math.max(n1, n2, n3, ..., nX)
พารามิเตอร์
Parameter | Description |
---|---|
n1, n2, n3, ..., nX | Optional. One or more numbers to compare |
คืนมูลค่า
: | ตัวเลข แทนจำนวนอาร์กิวเมนต์สูงสุด -Infinityหากไม่มีอาร์กิวเมนต์ NaNถ้าอาร์กิวเมนต์อย่างน้อยหนึ่งอาร์กิวเมนต์ไม่ใช่ตัวเลข |
---|