Skip to content

Commit 382a2ae

Browse files
committed
day 7 : functions - reviewed
1 parent 11b266b commit 382a2ae

1 file changed

Lines changed: 24 additions & 23 deletions

File tree

07_Day/07_day_functions.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
![Thirty Days Of JavaScript](../images/banners/day_1_7.png)
1919

20-
- [📔 Day 7](#%f0%9f%93%94-day-7)
20+
- [📔 Day 7](#-day-7)
2121
- [Functions](#functions)
2222
- [Function Declaration](#function-declaration)
2323
- [Function without a parameter and return](#function-without-a-parameter-and-return)
@@ -34,7 +34,7 @@
3434
- [Arrow Function](#arrow-function)
3535
- [Function with default parameters](#function-with-default-parameters)
3636
- [Function declaration versus Arrow function](#function-declaration-versus-arrow-function)
37-
- [💻 Exercises](#%f0%9f%92%bb-exercises)
37+
- [💻 Exercises](#-exercises)
3838
- [Exercises: Level 1](#exercises-level-1)
3939
- [Exercises: Level 2](#exercises-level-2)
4040
- [Exercises: Level 3](#exercises-level-3)
@@ -79,12 +79,13 @@ Function can be declared without a parameter.
7979
**Example:**
8080

8181
```js
82-
// function without parameter, a function which square a number
82+
// function without parameter, a function which make a number square
8383
function square() {
8484
let num = 2
8585
let sq = num * num
8686
console.log(sq)
8787
}
88+
8889
square() // 4
8990

9091
// function without parameter
@@ -95,33 +96,35 @@ function addTwoNumbers() {
9596

9697
console.log(sum)
9798
}
98-
addTwoNumbers() // function has to be called to be executed by it name
99+
100+
addTwoNumbers() // a function has to be called by its name to be executed
99101
```
100102

101103
```js
102-
function generateFullName (){
104+
function printFullName (){
103105
let firstName = 'Asabeneh'
104106
let lastName = 'Yetayeh'
105107
let space = ' '
106108
let fullName = firstName + space + lastName
107109
console.log(fullName)
108110
}
109-
generateFullName() // calling a function
111+
112+
printFullName() // calling a function
110113
```
111114

112115
### Function returning value
113116

114117
Function can also return values, if a function does not return values the value of the function is undefined. Let us write the above functions with return. From now on, we return value to a function instead of printing it.
115118

116119
```js
117-
function generateFullName (){
120+
function printFullName (){
118121
let firstName = 'Asabeneh'
119122
let lastName = 'Yetayeh'
120123
let space = ' '
121124
let fullName = firstName + space + lastName
122125
return fullName
123126
}
124-
console.log(generateFullName())
127+
console.log(printFullName())
125128
```
126129

127130
```js
@@ -170,19 +173,20 @@ function functionName(parm1, parm2) {
170173
//code goes her
171174
}
172175
functionName(parm1, parm2) // during calling or invoking two arguments needed
173-
// Function without parameter doesn't take input, so lets make a parameter with parameter
176+
// Function without parameter doesn't take input, so lets make a function with parameters
174177
function sumTwoNumbers(numOne, numTwo) {
175178
let sum = numOne + numTwo
176179
console.log(sum)
177180
}
178181
sumTwoNumbers(10, 20) // calling functions
179182
// If a function doesn't return it doesn't store data, so it should return
180-
function sumTwoNumbersAndReturn(numOne, numTwo) {
183+
184+
function sumTwoNumbers(numOne, numTwo) {
181185
let sum = numOne + numTwo
182186
return sum
183187
}
184188

185-
console.log(sumTwoNumbersAndReturn(10, 20))
189+
console.log(sumTwoNumbers(10, 20))
186190
function printFullName(firstName, lastName) {
187191
return `${firstName} ${lastName}`
188192
}
@@ -222,7 +226,7 @@ console.log(areaOfCircle(10))
222226

223227
### Function with unlimited number of parameters
224228

225-
Sometimes we do not know how many arguments the user going to pass. Therefore, we should know how to write a function which can take unlimited number of arguments. The way we do it has a significant difference between a function declaration(regular function) and arrow function.Let us see examples both in function declaration and arrow function.
229+
Sometimes we do not know how many arguments the user going to pass. Therefore, we should know how to write a function which can take unlimited number of arguments. The way we do it has a significant difference between a function declaration(regular function) and arrow function. Let us see examples both in function declaration and arrow function.
226230

227231
#### Unlimited number of parameters in regular function
228232

@@ -304,15 +308,9 @@ const anonymousFun = function() {
304308

305309
### Expression Function
306310

307-
Expression functions are anonymous functions. After we create a function without a name and with assign it to a variable. To return a value from the function we should call the variable. Look at the example below.
311+
Expression functions are anonymous functions. After we create a function without a name and we assign it to a variable. To return a value from the function we should call the variable. Look at the example below.
308312

309313
```js
310-
//Declaration function
311-
function square(n) {
312-
return n * n
313-
}
314-
315-
console.log(square(2)) // -> 4
316314

317315
// Function expression
318316
const square = function(n) {
@@ -342,7 +340,7 @@ console.log(squaredNum)
342340

343341
Arrow function is an alternative to write a function, however function declaration and arrow function have some minor differences.
344342

345-
Arrow function uses arrow instead of the keyword function to declare a function. Let us see both function declaration and arrow function.
343+
Arrow function uses arrow instead of the keyword *function* to declare a function. Let us see both function declaration and arrow function.
346344

347345
```js
348346
// This is how we write normal or declaration function
@@ -357,9 +355,10 @@ const square = n => {
357355
return n * n
358356
}
359357

360-
console.log(square(2)) // -> 4
361-
// if we have only one line, it can be written as follows, explicit return
362-
const square = n => n * n // -> 4
358+
console.log(square(2)) // -> 4
359+
360+
// if we have only one line in the code block, it can be written as follows, explicit return
361+
const square = n => n * n // -> 4
363362
```
364363

365364
```js
@@ -503,6 +502,8 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
503502

504503
### Function declaration versus Arrow function
505504

505+
It ill be covered in other time
506+
506507
🌕 You are a rising star, now you knew function . Now, you are super charged with the power of functions. You have just completed day 7 challenges and you are 7 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
507508

508509
## 💻 Exercises

0 commit comments

Comments
 (0)