首页 > 代码库 > ^_^判断奇偶

^_^判断奇偶

var isEven = function(n) {    return !(n&1) // & 按位与}console.log(1, isEven(1))console.log(25, isEven(25))console.log(138, isEven(138))var isEven = function(n) {    return !!n.toString().match(/[02468]$/)}console.log(1, isEven(1))console.log(25, isEven(25))console.log(138, isEven(138))var isEven = function(n) {    return !(n % 2)}console.log(1, isEven(1))console.log(25, isEven(25))console.log(138, isEven(138))

^_^判断奇偶