-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile46.js
61 lines (45 loc) · 1.43 KB
/
file46.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"use strict";
// arrow functions
// pattern for function arrow
// variable type function name = (params) => {
// do code here inside the function
// }
// function declarition
// function sumOfTwoNumber(a,b){
// let sum = a + b ;
// return sum;
// }
// sum1 = sumOfTwoNumber(2,12);
// console.log(sum1);
// function declarition to arrow function
const sumOfTwoNumber = (a,b) =>{
let sum = a + b ;
return sum;
}
let sum1 = sumOfTwoNumber(2,12);
console.log(sum1);
// function arrow
const checkTarget = (array,target) =>
{
for(let i =0 ; i<array.length;i++){
if (array[i] === target) {
return i;
}
}
return -1;
}
const myarray = [1,2,3,4,5,6,7,8,9,10];
const j = checkTarget(myarray,5);
console.log(j);
// VERY IMPORTANT CONSIDERATION IN ARROW Function
// condtion appies only for one liners
// if function is in one line then we don't need to use paranthics
// if function is one line then we also don't need to use retuen keyword
// let's see an example
const isEven = number => number % 2 === 0;
// calling function
console.log(isEven(4));
// one more example
// checking first index of any String
const chkStr = str =>str[0];
console.log(chkStr("jitendra"));