Skip to content

a为什么才能输出true

a 1 2 3

js
var a = {
    n : 1,
    valueOf() {
        return this.n++;
    }
};

console.log(a == 1 && a == 2 && a == 3)

a = 1 2 4

text

var a = {
    n : -1,
    valueOf() {
        this.n++;
        console.log(this.n)
        return  Math.pow(2, this.n)       
    }
};

console.log(a == 1 && a == 2 && a == 4)