I'm trying to discover when to use a function defined inside a variable as opposed to just a standalone function. Take the two tests below:
// test 1
function testFn(t) {
console.log(t);
}
for (let i = 0; i < 5; i++) {
testFn(i);
}
// test 2
var testFn2 = function _test(t) {
console.log(t);
}
for (let i = 0; i < 10; i++) {
testFn2(i);
}
The first test just uses a standalone function, whereas the second function uses a variable for the function. In what cases would I want to use one against the other? Could someone provide some clarification and advice here? Are both my functions correct in the above code?
Thanks for any help