DEV Community

SIYAMALA G
SIYAMALA G

Posted on

CALLBACK FUNCTION- EXAMPLES

What is callback Function ?
A function that you pass into another function, so it can be used (called) later.

1.Bus Travel :

function conductor(ticket){
    console.log("where to go");
     ticket();
}

function passenger()
{
    console.log("Ooty");
}

conductor(passenger);
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

where to go
Ooty
Enter fullscreen mode Exit fullscreen mode

2.G-pay process :

function Gpay(money){
    console.log("enter the amount");
    money();
}

function PIN(){
    console.log("enter the 4 digit PIN");
}

function credit(){
    console.log("sucessfully credited");
}
Gpay(PIN);
credit();
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

enter the amount
enter the 4 digit PIN
sucessfully credited
Enter fullscreen mode Exit fullscreen mode

3.Login Process:

function Web(signin){
    console.log("Email/Mobile no");
    signin();
}

function password(){
    console.log("enter your password");
}

function OTP(){
    console.log("enter otp");
}

function Login(){
    console.log("Sucessfully Login");
}
Web(password);
OTP();
Login();
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

Email/Mobile no
enter your password
enter otp
Sucessfully Login
Enter fullscreen mode Exit fullscreen mode

4.ClassRoom Attendance

function ClassA(attendance){
    console.log("Roll no 1");
}

function ask(){
    console.log("Aishwarya present");
}

function student1(){
    consolee.log("Rool.no 2");
}

function student2(){
    console.log("Bharathi present");
}
ClassA(ask);
student1();
student2();
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

Roll.no 1
Aishwarya present
Roll.no 2
Bharathi present
Enter fullscreen mode Exit fullscreen mode

5.ATM Machine Process

function ATM(Transaction){   
   console.log("domestic/International");
   Transaction();
 }
function step1(){
   console.log("click domestic");
 }
function step2(){
   console.log("click withdraw");
}
function step3(){
   console.log("enter your pin");
}
function step4(){
      console.log("enter the amount");
}
function step5(){
      console.log("collect your amount");
}
 function step6(){
      console.log("THANK YOU");
 }
 ATM(step1);
 step2();
 step3();
 step4();
 step5();
 step6();
Enter fullscreen mode Exit fullscreen mode

OUTPUT:

Domestic/International
click domestic
click withdraw
enter your pin
enter the amount
collect your amount
THANK YOU
Enter fullscreen mode Exit fullscreen mode

Top comments (0)