diff --git a/README.md b/README.md index f68fc1d4..869f8a05 100644 --- a/README.md +++ b/README.md @@ -550,6 +550,23 @@ // ... } ``` + + - Don't put side effect into default parameter + + > it introduces confusion and subtlety. Arguments in function call are evaluated at call site, but default parameters are not evaluated at define site. + + ```javascript + var b = 1 + // bad + function count(a = b++) { + console.log(a) + } + count() // 1 + count() // 2 + count(3) // 3 + count() // 3 + ``` + **[⬆ back to top](#table-of-contents)**