Added info about evaluation of default parameters

See issue #573 for reasoning.
This commit is contained in:
Mathias Bockwoldt 2018-11-14 09:47:30 +01:00 committed by GitHub
parent 991ca66d70
commit 43b1a82a37
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -204,6 +204,10 @@ function showMessage(from, text = anotherFunction()) {
} }
``` ```
```smart header="Evaluation of default parameters"
In JavaScript, a default parameter is evaluated every time the function is called without the respective parameter. In the example above, `anotherFunctions()` is called everytime `someMessage()` is called without the `text` parameter. This is in contrast to some other languages like Python, where any default parameters are evaluated only once during the initial interpretation.
```
````smart header="Default parameters old-style" ````smart header="Default parameters old-style"
Old editions of JavaScript did not support default parameters. So there are alternative ways to support them, that you can find mostly in the old scripts. Old editions of JavaScript did not support default parameters. So there are alternative ways to support them, that you can find mostly in the old scripts.