parseInt vs unary plus, when to use which?

后端 未结 5 628
终归单人心
终归单人心 2020-11-22 09:50

What are the differences between this line:

var a = parseInt(\"1\", 10); // a === 1

and this line

var a = +\"1\"; // a ===          


        
5条回答
  •  我在风中等你
    2020-11-22 10:28

    Be carefull, parseInt is faster than + unary operator in Node.JS, it's false that + or |0 are faster, them are faster only for NaN elements.

    Check this out:

    var arg=process.argv[2];
    
    rpt=20000;
    mrc=1000;
    
    a=[];
    b=1024*1024*1024*1024;
    for (var i=0;i

提交回复
热议问题