Following the question here:
JavaScript getting filename without extension located in different folder
I would like to concatenate this function with my string.
When I apply this code
"use strict";
window.addEventListener('load', onLoad, false);
function onLoad(evt) {
let scripts = document.querySelectorAll('script');
scripts.forEach(scr => {
if (scr.src != '') {
let slashPos = scr.src.lastIndexOf('/');
let filename = scr.src.slice(slashPos + 1);
filename = filename.replace('.js', '');
//console.log(filename);
return filename
}
});
}
var string = 'Date = ' + onLoad;
console.log(string)My console shows the full function instead of a certain date.
what should I do to have the date populated properly?

onLoad()function as an event handler for the "load" event, but then you want to call it? The function itself returnsundefinedbecause there is noreturnstatement except the one in the.forEach()callback, which will not have any effect.