Need help with forEach method

hey guys please take a look at this:

<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Arrays</h1>
<h2>The forEach() Method</h2>

<p>Call a function for each array element:</p>

<p id="demo"></p>

<script>
const fruits = ["Banana", "Orange", "Apple", "Mango"];

let text = "<ul>";
fruits.forEach(myFunction);
text += "</ul>";

document.getElementById("demo").innerHTML = text;

function myFunction(value) {
  text += "<li>" + value + "</li>";
} 
</script>

</body>
</html>

in this code i don’t get it why it used "value " at the end of the code. it’s not declared anywhere. “item” was also used in another code the same way as this one.

Its being used in the parameter (value). That is just like a placeholder. When you actually call the function value will be replaced with an actual value. That value is then used at the end of the code like you see.

So for example when I call the function


myFunction(“hi”) {
  

Where you made that function value will be “hi” even though you are using the word value

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.