Before I gave my JavaScript file type="module" , I could define my variables in the same statement that I used to return them.
Example:
function formatNameForFile(name) { return formattedName = name.toLowerCase().replace(/ /g, '-'); } However, once I did add type="module" to my JavaScript file, I received the following reference error:
Uncaught ReferenceError: formattedName is not defined I could eliminate these errors by explicitly defining my variables prior to returning them, like so:
function formatNameForFile(name) { const formattedName = name.toLowerCase().replace(/ /g, '-'); return formattedName; } Why is this? Aren't these variables still accessible via the initial return statement so long as they are bound (using const, var, or let) within it?
return name.toLowerCase().replace(/ /g, '-');.return name.toLowerCase().replace(/ /g, '-');