不可能的判定

题目描述

const a = ?;

if (a == 1 && a == 2 && a == 3) {
    console.log('不可能的判定发生了');
}

如上述代码,如何让不可能的判定成立?

解答

const a = {
    n: 1,
    // 方法一
    [Symbol.toPrimitive]() {
        console.log('symbol toprimitive被调用了');
        return this.n++;
    },

    // 方法二
    // valueOf() {
    //     console.log('value of 被调用了');
    //     return this.n++;
    // },

    // 方法三
    // toString() {
    //     console.log('toString被调用了');
    //     return this.n++;
    // }
};

if (a == 1 && a == 2 && a == 3) {
    console.log('不可能的判定发生了');
}

人心如良苗,得养乃滋长。苗以泉水灌,心以理义养。一日不读书,胸臆无佳想。一月不读书,耳目失精爽。
posted @ 2025-08-21 21:39  悦动代码  阅读(5)  评论(0)    收藏  举报