From 9f83b6b445111296c148e8382acf0b51451dac8b Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Thu, 18 Jan 2018 18:05:05 +0100 Subject: [PATCH 1/6] Wording --- 1-js/02-first-steps/14-function-basics/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 63ae4ff0..bbdec8cb 100644 --- a/1-js/02-first-steps/14-function-basics/article.md +++ b/1-js/02-first-steps/14-function-basics/article.md @@ -22,7 +22,7 @@ function showMessage() { } ``` -The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* in the brackets (empty in the example above) and finally the code of the function, also named "the function body". +The `function` keyword goes first, then goes the *name of the function*, then a list of *parameters* between the parentheses (empty in the example above) and finally the code of the function, also named "the function body", between curly braces. ![](function_basics.png) @@ -43,7 +43,7 @@ showMessage(); The call `showMessage()` executes the code of the function. Here we will see the message two times. -This example clearly demonstrates one of the main purposes of functions: to evade code duplication. +This example clearly demonstrates one of the main purposes of functions: to avoid code duplication. If we ever need to change the message or the way it is shown, it's enough to modify the code in one place: the function which outputs it. From 677cd6633d3070cb8ef3bc5c06ce5d1254e24316 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Thu, 18 Jan 2018 18:05:58 +0100 Subject: [PATCH 2/6] Typo --- 1-js/02-first-steps/14-function-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bbdec8cb..b1ac4ccd 100644 --- a/1-js/02-first-steps/14-function-basics/article.md +++ b/1-js/02-first-steps/14-function-basics/article.md @@ -119,7 +119,7 @@ function showMessage() { alert(message); } -// the function will create and use it's own userName +// the function will create and use its own userName showMessage(); alert( userName ); // *!*John*/!*, unchanged, the function did not access the outer variable From a54804bc0dbb5207afe0bf847cce304f6fc513fe Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Thu, 18 Jan 2018 18:09:01 +0100 Subject: [PATCH 3/6] Wording --- 1-js/02-first-steps/14-function-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 b1ac4ccd..867d10bc 100644 --- a/1-js/02-first-steps/14-function-basics/article.md +++ b/1-js/02-first-steps/14-function-basics/article.md @@ -130,7 +130,7 @@ Variables declared outside of any function, such as the outer `userName` in the Global variables are visible from any function (unless shadowed by locals). -Usually, a function declares all variables specific to its task, and global variables only store project-level data, so important that it really must be seen from anywhere. Modern code has few or no globals. Most variables reside in their functions. +Usually, a function declares all variables specific to its task. Global variables only store project-level data, so when it's important that these variables are accesible from anywhere. Modern code has few or no globals. Most variables reside in their functions. ``` ## Parameters From 089424e276f900f4218fcce634718e3c62965a11 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Thu, 18 Jan 2018 18:25:06 +0100 Subject: [PATCH 4/6] Missing words and typo --- 1-js/02-first-steps/14-function-basics/article.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 867d10bc..f4ade61e 100644 --- a/1-js/02-first-steps/14-function-basics/article.md +++ b/1-js/02-first-steps/14-function-basics/article.md @@ -378,7 +378,7 @@ These examples assume common meanings of prefixes. What they mean for you is det ```smart header="Ultrashort function names" Functions that are used *very often* sometimes have ultrashort names. -For example, [jQuery](http://jquery.com) framework defines a function `$`, [LoDash](http://lodash.com/) library has it's core function named `_`. +For example, the [jQuery](http://jquery.com) framework defines a function `$`. The [LoDash](http://lodash.com/) library has its core function named `_`. These are exceptions. Generally functions names should be concise, but descriptive. ``` From 3cdee0d73bc9bcfbffb8c13f5b8c21005c1e4f67 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Thu, 18 Jan 2018 18:30:06 +0100 Subject: [PATCH 5/6] Missing commas --- 1-js/02-first-steps/14-function-basics/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 f4ade61e..ff985e2e 100644 --- a/1-js/02-first-steps/14-function-basics/article.md +++ b/1-js/02-first-steps/14-function-basics/article.md @@ -426,7 +426,7 @@ function isPrime(n) { } ``` -The second variant is easier to understand isn't it? Instead of the code piece we see a name of the action (`isPrime`). Sometimes people refer to such code as *self-describing*. +The second variant is easier to understand, isn't it? Instead of the code piece we see a name of the action (`isPrime`). Sometimes people refer to such code as *self-describing*. So, functions can be created even if we don't intend to reuse them. They structure the code and make it readable. @@ -442,7 +442,7 @@ function name(parameters, delimited, by, comma) { - Values passed to a function as parameters are copied to its local variables. - A function may access outer variables. But it works only from inside out. The code outside of the function doesn't see its local variables. -- A function can return a value. If it doesn't then its result is `undefined`. +- A function can return a value. If it doesn't, then its result is `undefined`. To make the code clean and easy to understand, it's recommended to use mainly local variables and parameters in the function, not outer variables. From 18687748991b80e760b2120dfa2febe42e2286a5 Mon Sep 17 00:00:00 2001 From: Brent Guffens Date: Thu, 18 Jan 2018 18:31:04 +0100 Subject: [PATCH 6/6] Remove quotes around ternary operator --- .../14-function-basics/2-rewrite-function-question-or/task.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md b/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md index f70ad6fa..523bb127 100644 --- a/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md +++ b/1-js/02-first-steps/14-function-basics/2-rewrite-function-question-or/task.md @@ -22,5 +22,5 @@ Rewrite it, to perform the same, but without `if`, in a single line. Make two variants of `checkAge`: -1. Using a question mark operator `'?'` +1. Using a question mark operator `?` 2. Using OR `||`