Sunday 15 August 2010

javascript - Is there another way to initialize a variable in JS other than using the var key word? -


I was writing the function bills and it came to my mind that on asking if there is another way to counter variable Turn on other key loop using the key word? In addition, if it is possible in any other context, then not in any loop.

Obviously this code does not work.

  Each other (arr) function {var sum = 0; For (i = 0; i   

Does it work if I can exclude any kind of var keyword?

  Each other (arr) function {var sum = 0; (Var i = 0; i & lt; arr.length; i + = 2) {sum + = arr [i]; } Refund Amount; }    

it does work as a standalone It only sets the global i variable instead of using a local one. See.

However, when you call everyOther with another snippet that uses it global i variable, they can interfere especially if With any other loop, it can disturb the external condition and lead to an infinite loop.

No comments:

Post a Comment