Skip to content

Commit 79b7fa7

Browse files
committed
up
1 parent 864fcc9 commit 79b7fa7

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

1-js/2-first-steps/18-function-basics/article.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Function basics
1+
# Functions
22

33
Quite often we need to perform a similar action in many places of the script.
44

@@ -10,21 +10,23 @@ Functions are the main "building blocks" of the program. They allow the code to
1010

1111
We've already seen examples of built-in functions, like `alert(message)`, `prompt(message, default)` and `confirm(question)`. But we can create functions of our own as well.
1212

13-
## Definition
13+
## Function Declaration
1414

15-
An example of a function definition:
15+
To create a function we can use a *function declaration*.
16+
17+
It looks like this:
1618

1719
```js
1820
function showMessage() {
1921
alert( 'Hello everyone!' );
2022
}
2123
```
2224

23-
The `function` keyword goes first, then follows 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".
25+
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".
2426

2527
<img src="function_basics.png">
2628

27-
Once defined, the function can be called by it's name.
29+
Our new function can be called by it's name.
2830

2931
For instance:
3032

@@ -40,9 +42,9 @@ showMessage();
4042
*/!*
4143
```
4244

43-
The call executes the code of the function. Here we will see the message shown two times.
45+
The call `showMessage()` executes the code of the function. Here we will see the message two times.
4446

45-
In this example we can see one of the main purposes of the functions: to evade code duplication.
47+
This example clearly demonstrates one of the main purposes of the functions: to evade code duplication.
4648

4749
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.
4850

@@ -184,7 +186,7 @@ showMessage(from, "Hello");
184186
alert( from ); // Ann
185187
```
186188
187-
## Default parameter values
189+
### Default values
188190
189191
A function can be called with any number of arguments. If a parameter is not provided, but listed in the declaration, then its value becomes `undefined`.
190192

0 commit comments

Comments
 (0)