javascript var statement and performance

前端 未结 7 1516
后悔当初
后悔当初 2021-01-18 10:29

Option1 : multiple var without assignment

function MyFunction() {

  var a = null;
  var b = null;
  ....
  var z = null;

  a = SomeValue;
         


        
7条回答
  •  醉话见心
    2021-01-18 10:57

    "premature optimization is the root of all evil"

    I don't think there will be any significant performance change with any of this options.
    (IMO) The third option is the most readable option and closest to dynamic memory allocation like C# etc'. But this is my humble opinion, Choose what you like the most.

    If it really bothers you and you can't sleep without an answer, test it with jsPerf.


    @Chad made a jsPerf so you can sleep well tonight...

提交回复
热议问题