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"

 

posted @ 2018-12-05 15:17  大豆F4  阅读(196)  评论(0编辑  收藏  举报