From 43b1a82a372b5637096d6cddaa3fe4f74a5ddce8 Mon Sep 17 00:00:00 2001 From: Mathias Bockwoldt Date: Wed, 14 Nov 2018 09:47:30 +0100 Subject: [PATCH] Added info about evaluation of default parameters See issue #573 for reasoning. --- 1-js/02-first-steps/14-function-basics/article.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/1-js/02-first-steps/14-function-basics/article.md b/1-js/02-first-steps/14-function-basics/article.md index 3a7215a6..dd395a11 100644 --- a/1-js/02-first-steps/14-function-basics/article.md +++ b/1-js/02-first-steps/14-function-basics/article.md @@ -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" 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.