Is it bad practice to not assign a new object to a variable?

前端 未结 5 715
孤街浪徒
孤街浪徒 2020-12-28 18:56

Is it bad javascript practice to not assign a newly created object to a variable if you\'re never going to access it?

For example:

for(var i=0;i

        
5条回答
  •  佛祖请我去吃肉
    2020-12-28 19:49

    "Is it bad javascript practice to not assign a newly created object to a variable if you're never going to access it?"

    I feel it is bad practice to make an assignment that is not needed, and, I would argue, not just for javascript but in general. If there are side-effects you want, getting them from the action of an assignment is bad practice for the simple reason that it would be fairly opaque from a maintenance point of view.

    .

提交回复
热议问题