Get to know MDN better
The JavaScript exception ""use strict" not allowed in function" occurs when a "use strict" directive is used at the top of a function with default parameters, rest parameters, or destructuring parameters.
A "use strict" directive is written at the top of a function that has one of the following parameters:
A "use strict" directive is not allowed at the top of such functions per the ECMAScript specification.
In this case, the function sum has default parameters a=1 and b=2:
If the function should be in strict mode, and the entire script or enclosing function is also okay to be in strict mode, you can move the "use strict" directive outside of the function:
A function expression can use yet another workaround:
This can be converted to the following expression:
If an arrow function needs to access the this variable, you can use the arrow function as the enclosing function:
This can be converted to the following expression:
This page was last modified on Jul 8, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.