Declaring an internal function in JS may be due to lexical binding of local variables / arguments to the external variable. Moving it for a top-level function hits this target.
To answer the question: yes, an internal function is created every time, at least theoretically, and that is how you should look at it when writing code, but the intelligent optimizer can convert it to a top-level function, even if you have lexical dependencies. If itβs micro-optimization, I wouldnβt worry, because the internal function also serves to read and announce your intentions.
Erik allik
source share