Javascript string/integer comparisons

后端 未结 8 1084
太阳男子
太阳男子 2020-11-22 16:34

I store some parameters client-side in HTML and then need to compare them as integers. Unfortunately I have come across a serious bug that I cannot explain. The bug seems to

8条回答
  •  忘掉有多难
    2020-11-22 17:22

    Comparing Numbers to String Equivalents Without Using parseInt

    console.log(Number('2') > Number('10'));
    console.log( ('2'/1) > ('10'/1) );
    
    var item = { id: 998 }, id = '998';
    var isEqual = (item.id.toString() === id.toString());
    isEqual;
    

提交回复
热议问题