-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile132.js
More file actions
90 lines (62 loc) · 2.4 KB
/
Copy pathfile132.js
File metadata and controls
90 lines (62 loc) · 2.4 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"use strict";
// Understanding callback
// calling function inside of the function
function myfunc(callback){
console.log("performing myfunc function");
callback();
}
function myfunc2(){
console.log("performing myfunc2 2 function task 2");
}
// myfunc(myfunc2);
// or i can do this work directly
// myfunc( ()=>{
// console.log("performing myfunc2 2 function task 2");
// } );
// let's understand it with the second simple example
function printTwoNumbersWithAdd(number1 , number2 , atSucces , atFailier){
if( typeof number1 === "number" && typeof number2 === "number"){
console.log(number1,number2);
atSucces(number1 , number2);
}
else{
atFailier();
// console.log("wrong type");
}
// here i was making mistake because i was not adding these value inside the callBack function
}
function failCase(){
console.log("wrong type");
console.log("please enter right data type");
}
// now here i'm creating second function for callback in that function i will add them
function addNumber(num1 , num2){
console.log(num1 + num2);
}
// printTwoNumbersWithAdd(4,5,addNumber);
// or i can directly call this function inside the function
printTwoNumbersWithAdd(4,"6", (num1,num2)=>
{
console.log(num1+num2);
} , failCase );
// more case with my more understanding about callbacks
function mainFunc(mynum1 , mynum2 ,multiply ,addition ){
// check number is smaller then 100 or not if it is then go for multiple otherwise add them using callback
// if(mynum1 || mynum2 < 60){
if((mynum1<60) && (mynum2<60)){
multiply(mynum1,mynum2) ;
// console.log("multi working");
}
else{
addition(mynum1 , mynum2);
}
}
// now here i will crate callback functions name => multiple ,addition
const MultiplecationFunc = (num1,num2)=>{console.log(`your multiplication number is : ${num1*num2}`);
console.log("both values are under 60");}
const additionFunc = (num1,num2)=>{console.log(`your addition value is : ${num1+num2}`);
console.log("one or more value is more then 60")
}
// calling mainfunction here for output
// adition will be applied only when both of numbers are below 60
mainFunc( 22 , 28 , MultiplecationFunc , additionFunc);