javascript var statement and performance

前端 未结 7 1579
后悔当初
后悔当初 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:55

    Just stay away from option 1 if possible, there is no need to make two assignments.

    Even variables declared inside a for loop or other compound statement/block will be available outside its containing block.

    You can also do:

    function MyFunction() {
    
      var a = SomeValue, b = SomeVavlue2;
    
    }
    

提交回复
热议问题