Skip to content

Commit 0881deb

Browse files
committed
Declaring Functions notes
1 parent 06f9987 commit 0881deb

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

functions/declare.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ function double(x) {
88
}
99
```
1010

11+
>*Note:* the function above **may** be referenced before it has been defined.
12+
1113
Functions are also values in JavaScript; they can be stored in variables (just like numbers, strings, etc ...) and given to other functions as arguments :
1214

1315
```javascript
@@ -16,6 +18,8 @@ var double = function(x) {
1618
};
1719
```
1820

21+
>*Note:* the function above **may not** be referenced before it is defined, just like any other variable.
22+
1923
---
2024

2125
Declare a function named `triple` that takes an argument and returns its triple.

functions/declare.md~

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Declaring Functions
2+
3+
Functions, like variables, must be declared. Let's declare a function `double` that accepts an **argument** called `x` and **returns** the double of x :
4+
5+
```javascript
6+
function double(x) {
7+
return 2 * x;
8+
}
9+
```
10+
11+
*Note*: the function above **may** be referenced before it has been defined.
12+
13+
Functions are also values in JavaScript; they can be stored in variables (just like numbers, strings, etc ...) and given to other functions as arguments :
14+
15+
```javascript
16+
var double = function(x) {
17+
return 2 * x;
18+
};
19+
```
20+
21+
*Note*: the function above **may not** be referenced before it is defined, just like any other variable.
22+
23+
---
24+
25+
Declare a function named `triple` that takes an argument and returns its triple.
26+
27+
```js
28+
29+
```
30+
31+
```js
32+
var triple = function(x) {
33+
return x * 3;
34+
}
35+
```
36+
37+
```js
38+
assert(triple);
39+
assert(triple(4) === 12);
40+
assert(triple(10) === 30);
41+
```
42+
43+
---
44+

0 commit comments

Comments
 (0)