Sunday, October 24, 2021

Call Back Functions in Javascript

 <!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>Call Back Function</title>

</head>

<body>

<h1>Students List</h1>

<ul id="name"></ul>

<script type="text/javascript">

const students = [

             

             {name : "atul", subject : "Computer Science"},

             {name : "ashish", subject : "Computer Network"}


]


function setStudents(something, callBack) {

               setTimeout(function(){

                    students.push(something);

                    console.log("Student Updated");

                    callBack();

               }, 3000);

}

        

        function getStudents() {

        setTimeout(function(){

               var str = "";

               students.forEach(function(args){

                str = str + `<li>${args.name}</li>`

               });

               document.getElementById('name').innerHTML = str;

               console.log("Hey showing Students");

        }, 1000)

        }


        var jayega = {name : "pradeep", subject : "Android"}

        setStudents(jayega, getStudents);

      


</script>


</body>

</html>


yaha par setStudent getStudent ko rok kar rakhega jabtak ki wo khud execute nahi ho jata



No comments:

Post a Comment

Priority queue deleting elements after ascending inputs Gaand Fadd

 using namespace std; #include<iostream> #define N 5 class pq { public:     int* arr;     int front;     int rear;     pq() {         ...