It's just what the error message says:
functions can only be declared at top level or immediately within another function
You must not put a function declaration inside any other block, like an if-statement or for-loop.
Example:
'use strict';
function some() {
function okay() {
}
let x = 1;
function no_problem() {
}
if (x == 1) {
function BOOM() { // <- wrong!
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…