Skip to main content
Add link from comment to source of claim
Source Link
jmoreno
  • 11.2k
  • 1
  • 33
  • 50

I recently read somewhere somewhere that calling a function within a loop is considered bad practice. Is this true? So for example, if I had the following:

function foo(value){
    console.log(value);
}

var bar = ["Foo", "Bar"];

for(var i = 0; i < bar.length; i++){
    foo(bar[i]);
}

Is it bad practice do do this? Should there be another way I should be calling foo?

Note: This question is not specific to Javascript, it's just what I wrote the question in.

I recently read somewhere that calling a function within a loop is considered bad practice. Is this true? So for example, if I had the following:

function foo(value){
    console.log(value);
}

var bar = ["Foo", "Bar"];

for(var i = 0; i < bar.length; i++){
    foo(bar[i]);
}

Is it bad practice do do this? Should there be another way I should be calling foo?

Note: This question is not specific to Javascript, it's just what I wrote the question in.

I recently read somewhere that calling a function within a loop is considered bad practice. Is this true? So for example, if I had the following:

function foo(value){
    console.log(value);
}

var bar = ["Foo", "Bar"];

for(var i = 0; i < bar.length; i++){
    foo(bar[i]);
}

Is it bad practice do do this? Should there be another way I should be calling foo?

Note: This question is not specific to Javascript, it's just what I wrote the question in.

Tweeted twitter.com/StackProgrammer/status/720211249833840640
Source Link
Robert
  • 225
  • 1
  • 2
  • 4

Is using a function inside a for loop bad practice?

I recently read somewhere that calling a function within a loop is considered bad practice. Is this true? So for example, if I had the following:

function foo(value){
    console.log(value);
}

var bar = ["Foo", "Bar"];

for(var i = 0; i < bar.length; i++){
    foo(bar[i]);
}

Is it bad practice do do this? Should there be another way I should be calling foo?

Note: This question is not specific to Javascript, it's just what I wrote the question in.