switch使用中遇到的问题

switch分支语句中case判断不会进行隐式数据类型转换;

const fn = (value) => {
    switch (value) {
        case '':
            return 'all0';
        case '3':
            return 'all3';
        case '4':
            return 'all4';
        case '6':
            return 'all6';
        case '7':
            return 'all7';
        case '8':
            return 'all8';
        case '9':
            return 'all9';
        default:
            return 'all10';
    }
};

fn(9);
// 预期运行结果为: "all9"
// 实际运行结果为: "all10"
原文地址:https://www.cnblogs.com/dadouF4/p/10071098.html