Promises Basics, Promise.then() & Promise.catch() | JavaScript Tutorial In Hindi #39

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024

Комментарии • 383

  • @anantvaid7606
    @anantvaid7606 5 лет назад +80

    Bhai, I was trying to learn this from different sites bit was not able to understand. But aapne kya samjhaaya hai🔥. Love you bhai, aapka data science ka bhi playlist mast hai. All the best bhai ❤️.

  • @aniloli
    @aniloli 3 года назад +47

    small try:
    function checkpwd(pass) {
    return new Promise((resolve, reject) => {
    setTimeout(() => {
    const defaultPass = "admin";
    defaultPass == pass ? resolve() : reject();
    }, 1000);
    });
    }
    let passEntered = "harry";
    checkpwd(passEntered)
    .then(() => {
    console.log("Password matched");
    })
    .catch(() => {
    console.log("Access Denied");
    });

  • @vishwasagrawal4700
    @vishwasagrawal4700 4 года назад +21

    Promise.then(console.log('harry bhai explained and fulfiled the promise').catch(console.log('ye kabhi print hi nhi hoga')

  • @preetiharjani1654
    @preetiharjani1654 4 года назад +38

    i tried oddEven exercise with promise:
    console.log('tut38(quiz)');
    function oddEven() {
    return new Promise(function (resolve, reject) {
    setTimeout(function () {
    let n = 45;
    if (n % 2 == 0) {
    console.log('number is even');
    resolve();
    }
    else {
    console.log('number is odd');
    reject();
    }
    }, 5000);
    })
    }
    oddEven().then(function () {
    console.log("Task resolved");
    }).catch(function () {
    console.log("Oops!!Task rejected");
    })

    • @oook3407
      @oook3407 Год назад

      jan aap nay bht piyara function banaya ha

    • @avipraidey5767
      @avipraidey5767 Год назад

      Very good 😊🙌

    • @hamidsahi4357
      @hamidsahi4357 Год назад

      but we can do same thing by using simple function so whats the difference question

  • @the_xibalba
    @the_xibalba 3 года назад +4

    I stumbled upon this video while searching for tutorials on promises, I had been so confused all this time. This worked for me! Thank you Bhai!

  • @bisworajsaheb4171
    @bisworajsaheb4171 4 года назад +8

    Watching right after a year. Wish I had found it before. Thanks Harry bhai.

  • @akankshapatel9508
    @akankshapatel9508 2 года назад +9

    Very useful to understand this during my internship phase thank you!!!!!!

    • @Blackfeather7777
      @Blackfeather7777 Год назад

      Hi can you help me with what questions you faced during your js interview ?

  • @pratikpawar376
    @pratikpawar376 3 года назад +6

    //Harry bhi ka promise
    function pratikpromise(){
    return new Promise(function(resolve, reject){
    setTimeout(()=>{
    let error = false;
    if(!error){
    console.log("Harry bhai ka video dekha samaj me aa chuka hai as per the promise of harry bhai");
    resolve();
    }
    else{
    console.log("Harry bhai ka video phir se dekh le samaj aa jayega");
    reject();
    }
    }, 1000)
    });
    }
    pratikpromise().then(
    function()
    {
    console.log("Thank you So much Harry Bhai");
    }).catch(function()
    {
    console.log("Sorry Harry bhai, lekin koshis karuga samaj ne ki")
    });

  • @rajputayush6066
    @rajputayush6066 3 года назад +47

    function myFun(num1,num2){
    return new Promise(function(resolve,reject){
    if((num1+num2) >50){
    resolve();
    }else{
    reject();
    }
    });
    }
    myFun(70,30).then(function(){console.log("Number Is Greater then 50 ")}).catch(function(err){console.log("Number is less then 50")});

    • @andressergio1532
      @andressergio1532 3 года назад +1

      sorry to be so offtopic but does anyone know of a method to log back into an Instagram account..?
      I somehow lost my password. I would love any help you can give me

    • @ikeroliver7186
      @ikeroliver7186 3 года назад

      @Andres Sergio instablaster ;)

    • @andressergio1532
      @andressergio1532 3 года назад +1

      @Iker Oliver I really appreciate your reply. I found the site thru google and im waiting for the hacking stuff atm.
      Looks like it's gonna take a while so I will reply here later with my results.

    • @andressergio1532
      @andressergio1532 3 года назад

      @Iker Oliver It did the trick and I actually got access to my account again. Im so happy!
      Thanks so much you saved my ass!

    • @ikeroliver7186
      @ikeroliver7186 3 года назад

      @Andres Sergio you are welcome xD

  • @karanludhani6072
    @karanludhani6072 5 лет назад +3

    Harry bhai dsa k lectures b jaldi upload kijiye... Hm logo k interviews ka time aa gya hai. Or apke lectures se bahot help milti hai.. thank you so much for giving all these contents

  • @madhavjaveri1478
    @madhavjaveri1478 3 года назад +2

    var marks=prompt("enter marks");
    function papaPromise(){
    return new Promise(function(resolve,reject){
    score = parseInt(marks);
    if (score

  • @abhisekupadhaya
    @abhisekupadhaya 5 лет назад +4

    Sir, You are best RUclips programmer.
    Please, Make tutorial on OpenCV for python. I want to apply OpenCV in Machine Learning.

  • @muhdanidanidarkdyce407
    @muhdanidanidarkdyce407 4 года назад +4

    Behtareen hogaya bhai... harry Bhai aap se Dil lagi hogai he yaar....💞💕❣️💌❤️💝💟💓💗💖
    Ab aapke saaray coarses bhi dekhne ka iraada ban Gaya he...
    Love you 😘😘😘
    From Pakistan ❣️

  • @nielltalwar1574
    @nielltalwar1574 2 года назад +1

    thanks harry for such a brilliant and simple explaination. here is my practise
    let p1=new Promise((resolve,reject)=>{
    let input=prompt("enter a number");
    if(input%2==0){
    console.log("even number");
    resolve("Hurray");
    }
    else{
    console.log("odd number");
    reject("oh no!");
    }
    });
    p1.then((msg)=>{console.log(msg);
    return new Promise((resolve,reject)=>{
    let name=prompt("enter your name");
    if(name=="nitin"){
    resolve();
    }
    else{
    reject();
    }
    })
    }).then(console.log("Nitin found. balle balle!")).catch((err)=>console.log("Promise rejected!",err));

  • @codewsohan
    @codewsohan 3 года назад +26

    You resolved your promise. Great explanation ! Loved it ♥️

  • @shreenidhideshpande
    @shreenidhideshpande 4 года назад +5

    I think I searched all sites, books but not got the concepts this much clear . Thank you very much Bhai. please make a series on react and node too

  • @harshchopra1588
    @harshchopra1588 3 года назад +2

    Thanks Harry bhai!
    Your Quiz solution is here:
    function dish(){
    return new Promise(function(resolve, reject){
    setTimeout(() => {
    const error = false;
    if(!error)
    {
    console.log("Yes!promise is resolved");
    resolve();
    }
    else
    {
    console.log("No!promise is not resolved");
    }
    }, 4000);
    })
    }
    dish().then(function(){
    console.log("Dish was tasty");
    }).catch(function(){
    console.log("Dish was insipid");
    });

    • @karanveersingh5535
      @karanveersingh5535 3 года назад

      U haven't put reject() then what's the point of putting .catch() function .It won't be called .

  • @maaz1150
    @maaz1150 4 года назад +10

    Learning my entire engineering from here. Thank you.

  • @Shillu1988
    @Shillu1988 4 года назад +7

    Finally Today I have understand Promises, Thanks Bro

    • @av1shek_ps
      @av1shek_ps 4 года назад

      Can any one explain me or give me code how to use setTimeout in promise?
      Is it necessary to define function in promise only can we not give only name of function there and define it at any other place.

    • @av1shek_ps
      @av1shek_ps 4 года назад

      Bro if you know can you explain me

    • @av1shek_ps
      @av1shek_ps 4 года назад +1

      //Can anyone tell me how to wrap it with setTimeout function
      console.log('Now you are online.');
      function callingfun() {
      return new Promise(function (resolve, reject) {
      let xhr = new XMLHttpRequest();
      xhr.open('GET', 'kk1.txt', true);
      xhr.onload = function () {
      if (this.status === 200) {
      console.log(this.responseText);
      resolve();
      }
      else {
      console.log('some error occured');
      reject();
      }
      }
      xhr.send();
      })
      }
      callingfun().then(function () { console.log('promise resolved'); }).catch(function () { console.log('promise rejected') });

    • @Virus-ke8xj
      @Virus-ke8xj 4 года назад

      @@av1shek_ps I think there's no point in using setTimeout function over here, I mean, what you are doing is sending a get request and checking the status of the response, there's not time involved right?
      If u want you can add it, but here it seems to be illogical

    • @Virus-ke8xj
      @Virus-ke8xj 4 года назад

      Just wrap everything starting from initialisation of XML object to the end inside the setTimeout function

  • @sohamnesarikar5516
    @sohamnesarikar5516 4 года назад +4

    Harry bhai...apne promise pura kiya...samaj aa gaya promise😄❤️

  • @sourabhsivare1876
    @sourabhsivare1876 2 года назад +2

    Bro great explaining, hats off to your efforts

  • @umergillani5046
    @umergillani5046 3 года назад +26

    Love from Pakistan Karachi❤️

  • @AkshitSangwan-v8l
    @AkshitSangwan-v8l Год назад

    Best Expalanation ever in the most layman language.

  • @prajwalzingare7332
    @prajwalzingare7332 2 года назад

    function number(n1, n2) {
    return new Promise((resolve, reject) => {
    if (n1 >= 0 || n2 >= 0) {
    console.log("Function: your promise has been resolved");
    resolve(n1 + n2);
    } else {
    console.log("Function:your promise has not been resolved");
    reject("sorry not fullfilled ");
    }
    });
    }
    number(10, -20)
    .then((result) => {
    console.log("prajwal:Thanks for resolving " + result);
    })
    .catch((error) => {
    console.log("prajwal:very bad" + error);
    });
    great explanation thanks harry bhaii❤❤

  • @muneebzubair5069
    @muneebzubair5069 3 года назад +3

    promise resolved() with Love from Pakistan Lahore Punjab ❤️

  • @Satish_Kumar_Gupta
    @Satish_Kumar_Gupta 4 года назад +1

    harry bhai aapne apna best promise video ko successfully resolve kar liya. Thank you so much...:)

  • @hassanahmed8216
    @hassanahmed8216 2 года назад +2

    Amazing explanation!!!❤️❤️❤️

  • @Saifolic
    @Saifolic 4 года назад +2

    it's really very useful thanks a lot

  • @rpnrko3612
    @rpnrko3612 2 года назад

    Understood in one go. Patte se headshot Harry bhai!!!

  • @vikaschauhan-rv6fi
    @vikaschauhan-rv6fi 3 года назад

    starting mai laga tha ki nahi aayega samajh mai, par 1 dum badiya se samajh aagaya

  • @dr.ramkishorsah495
    @dr.ramkishorsah495 4 года назад +1

    waah kya explanation so easy to understand to learn a complex thing. Salute🤘🙏🙏🙏

  • @vivekkumar-pc1xy
    @vivekkumar-pc1xy 2 года назад

    mein just abhi brad traversy ka lecture attend kiya tha udemy se, Promises ka. Difference itna hai apne us lecture ko hindi mein explain kr diya. But mughe ab smgh agya

  • @TechnicalAnkesh
    @TechnicalAnkesh 3 года назад +3

    Harry bro as always you resolved your promise LOVED YOUR EXPLANATION🤩🥰

  • @abhimalvekr127
    @abhimalvekr127 4 года назад +1

    Good one bro. Bohot ache se samjhaya bhai ne! Keep up the good work

  • @kartikeykakaria8a168
    @kartikeykakaria8a168 3 года назад

    Sir maine kahi jyada jagahon se promises sikhne ki koshish ki par samajh nahi aaya par aapki video dekhke pehli bar mein hi samajh aa gya. You the best programmer on youtube! One request : pls make a tutorial on sql also please :)

    • @aevanvaghani3593
      @aevanvaghani3593 Год назад

      okkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkl.

  • @fattehalisunasarasunasara4111
    @fattehalisunasarasunasara4111 5 лет назад +2

    Sir materialize css ki series banavo please

  • @javeriyakhan1773
    @javeriyakhan1773 2 года назад

    promise resolved!! well explained!!👍

  • @paramsaini6932
    @paramsaini6932 2 года назад

    Best In The World (ABOVE ALL) THANKS bro

  • @anantraj1071
    @anantraj1071 4 года назад

    harry bhai ...bht jagh se try kra kia but atlast yha jake samjh aaya thnxxx bhaii!!!!!

  • @sports4yoo
    @sports4yoo 2 года назад

    3M Soon Harry Bhai
    big congratulations in advance 🎉❤

  • @harshpreetsingh6971
    @harshpreetsingh6971 2 года назад +1

    Thanks for resolving your promise ♥️🙏💯

  • @deepakchillal3553
    @deepakchillal3553 Год назад

    I initially watches your promises on ultimate javascript course very confusing there here clearring explained my suggestion kindly upload this in that playlist

  • @travelnlearn
    @travelnlearn 2 года назад +1

    mast hai bhai maja aa gaya

  • @anubhavverma1591
    @anubhavverma1591 Год назад

    Promise Resolved Thanks Harry ❤

  • @ibtehaj95
    @ibtehaj95 Год назад

    Thanks a lot bro. You explained it very well.

  • @Rahulyadav-ry1lk
    @Rahulyadav-ry1lk 5 лет назад +6

    Sir ke fan like thoko👈👌🤙

  • @parmarmayank7087
    @parmarmayank7087 4 года назад +1

    You are amazing brother. God bless you

  • @utkarshsingh2912
    @utkarshsingh2912 2 года назад

    console.log('Promise Quiz')
    function promise(){
    return new Promise(function(resolve, reject){
    let understood = true;
    if(understood){
    resolve();
    }
    else{
    reject();
    }
    });
    }
    promise().then(()=>{
    console.log('Thankyou harry bhai sab samjh me aagya');
    }).catch(()=>{
    console.log('Samjh ni aya')
    })

  • @savanpatel9641
    @savanpatel9641 4 года назад

    thank you bhai ...........u r d best youtube programmer ever................

  • @TheCuratedUX
    @TheCuratedUX 2 года назад +1

    great content

  • @tanmoyhaldar4514
    @tanmoyhaldar4514 3 года назад +1

    I think my iitkkgp profs will also not teach me like this. Loved the way you used examples.

  • @mrinalraj7166
    @mrinalraj7166 2 года назад

    Thank you harry bhai. You are god.

  • @harshmudgil4140
    @harshmudgil4140 4 года назад

    The way you are explaining is really good.

  • @shrutigoyal3494
    @shrutigoyal3494 4 года назад +1

    you nailed it. and yes it is a resolve.

  • @javascriptwar9525
    @javascriptwar9525 4 года назад +1

    you save my life brother..🙌awesome

  • @Hassanali-tj1kq
    @Hassanali-tj1kq 2 года назад

    bhi muzy tu maza a agya phr na ma mara pura samj ma a gaya thank you bhi

  • @osamakhan2552
    @osamakhan2552 2 года назад

    I have watch this video 4 time now finally i'm understand 😍

  • @ayushajayuzfmvwfenu7720
    @ayushajayuzfmvwfenu7720 3 года назад +1

    after buying the Coding ninja web dev course, come here to catch on, easy to understand video loved it ❤️

  • @KnoxFTW
    @KnoxFTW 5 лет назад +1

    Bhaiya please make video on Android Development .

  • @bantisharma8119
    @bantisharma8119 4 года назад

    Best Video for learning Javascript.
    Thank you harry bhai

  • @ajinkyajadhav8049
    @ajinkyajadhav8049 3 года назад +2

    function sum(a,b){
    return new Promise (function(resolve, reject){
    let c = a+b;
    if (c >100){
    console.log("Sum of A and B is : ",c)
    resolve("sum is greater than 100")
    }
    else{
    console.log("Sum of A and B is : ",c)
    reject("sum is less than 100")
    }
    })
    }
    sum(10,23).then(function(a){
    console.log(a);
    }).catch(function(b){
    console.log(b)
    })

  • @moderngypsy5980
    @moderngypsy5980 2 года назад

    How should I thank you Harry bhai, you are the best..

  • @vipinsaini3497
    @vipinsaini3497 4 года назад +1

    Hi.
    Your tutorial is informative.
    I loved it.
    Thanks for sharing and keep the good work going

  • @thevarunparashar
    @thevarunparashar 4 года назад +1

    You are an amazing guy... keep it up

  • @akashsolanki5570
    @akashsolanki5570 3 года назад +1

    @codewithharry please explain the Promise constructor. Isn't it supposed to make a object, which should look like this {...} when we do console.log(func1())

    • @ibtehaj95
      @ibtehaj95 Год назад

      Yes, Promise will create a new object. Harry just chained more stuff to it and probably displayed it (I don't remember the timestamp). I wrote very simple code to make myself understand, it might help.
      ///////My Code////////////
      let oath_keeper = 0;
      const promiss = new Promise(function(accept, excuse){
      if(oath_keeper === 1){
      accept("Oath Kept");
      }
      else{
      excuse("Oath Broken");
      }
      });
      promiss.then(function(message){
      console.log(`Message from Promiser: ${message}`);
      }).catch(function(message){
      console.log(`Message from Promiser: ${message}`);;
      });

  • @rishabhtripathi3569
    @rishabhtripathi3569 3 года назад +1

    17:36 explanation

  • @parshantmadaan4709
    @parshantmadaan4709 Год назад

    Your promise resolved Thanks

  • @vieharchives8208
    @vieharchives8208 2 года назад +1

    // If you know Python, this concept is similar to Try and Except.
    // Here is simple example of Promises
    function oddEven(number) {
    return new Promise(function (resolve, reject) {
    if (number%2==0) {
    resolve();
    } else {
    reject();
    }
    })
    }
    oddEven(16).then(function () {
    console.log("Your number is Even")
    }).catch(function () {
    console.log("Your Number is Odd");
    })

  • @yashwantsahu1752
    @yashwantsahu1752 4 года назад

    promise done perfect harry bhai ...

  • @webprogramminghindiurdu3279
    @webprogramminghindiurdu3279 4 года назад

    Bohut acha explain kiya bhai ap ney

  • @MuhammadBilal-fw7gh
    @MuhammadBilal-fw7gh 2 года назад

    Harry bhai you really resolved your promise❤😉

  • @karthikjoshi6386
    @karthikjoshi6386 3 года назад +1

    Famous club concept if (age

  • @VedPrakash-kf6kv
    @VedPrakash-kf6kv 2 года назад

    congratulation for 2million hary bhai

  • @Rahulyadav-ry1lk
    @Rahulyadav-ry1lk 5 лет назад +1

    Fantastic

  • @khelanmehta1554
    @khelanmehta1554 3 года назад

    Awesomeeeee bro dhang se samhjha diya tune

  • @anaskhan4841
    @anaskhan4841 3 года назад

    Much Much Appreciated Harry Bhai...

  • @barshaproduction7281
    @barshaproduction7281 4 года назад +1

    Bahat try kiya samajne k liye but humko samaj nahi aha raha ha ki ye promise use q kare?

  • @Travelmoments
    @Travelmoments 4 года назад

    Sabashhhh!!!!! bhahut badiya samjaya apne..

  • @shaheensiddiqui1952
    @shaheensiddiqui1952 2 года назад

    sir we are always see you full vidio

  • @subhasishsahu9749
    @subhasishsahu9749 3 года назад

    thanks bro i was so confused about this and you helped me a lot .

  • @vaibhavkulkarni5601
    @vaibhavkulkarni5601 4 года назад

    Very nicely explained Harry bhai !!

  • @msbasera
    @msbasera 2 года назад

    Thank you bhai ❤️

  • @lopamudrasahu2202
    @lopamudrasahu2202 2 года назад

    superb brother

  • @prabhatkumar5242
    @prabhatkumar5242 4 года назад +4

    // Promise To Resolve if the given time is less than 2 sec or it will Reject.
    function delay(time) {
    return new Promise((resolve , reject) => {
    if (time resolve( "Resolve : " + "Time is less or equal to 2 sec"), time)
    }
    else {
    reject("Reject : " +"Time is more than 2 sec")
    }
    })
    }
    delay(2000)
    .then((res) => console.log(res))
    .catch((err) => console.log(err))

  • @nayankumarshit7522
    @nayankumarshit7522 5 лет назад

    Harry bhai i like your django tutorials.. love you vai

  • @pushkarkumar5578
    @pushkarkumar5578 4 года назад

    bhai gajab padhate hoo app maja agaya :*

  • @laxmipriyapradhan1704
    @laxmipriyapradhan1704 2 года назад

    Please harry kya ap ye 4 concept ko milake ek website banana sikha sakte ho please please please🙏
    - Generator
    - Promises
    - AJAX Request -
    - Callback Function

  • @TheAddictiveVibe
    @TheAddictiveVibe 3 года назад +1

    function deleteStudent(index){
    console.log("indise delete",student)
    return new Promise(function(resolve,reject){
    student.splice(index,1)
    const error = true;
    if (error) {
    resolve();
    }
    else {
    reject();
    }
    });
    }
    deleteStudent(0).then(success).catch(failure);
    function success(){
    console.log("Successfully Delete" , student)
    }
    function failure(){
    console.log("Something went wrong", student)
    }

  • @pranaykosulkar641
    @pranaykosulkar641 3 года назад

    Harry Bhai you resolved your promise 🙏 ❤️👍

  • @sahllsaharn4664
    @sahllsaharn4664 2 года назад

    so bhaiya callbacks and promises are used to synchronize JS

  • @mr.curious1714
    @mr.curious1714 3 года назад

    Promise is resolved by Harry Sir

  • @hmmmza
    @hmmmza 2 года назад +3

    function isDay(hours){
    return new Promise(yes, no){
    if(hours>5 && hours

  • @iamSadabAlvi
    @iamSadabAlvi 5 лет назад

    I am always ready for your video
    Like too banta hai

  • @aasrivastava5851
    @aasrivastava5851 5 лет назад +1

    Your videos are very good sir.Appreciate your youtube work.
    Please make a video on AJAX

    • @CodeWithHarry
      @CodeWithHarry  5 лет назад +3

      I have already uploaded a video no Ajax with title "Ajax tutorial in hindi"
      Kindly access the playlist!

    • @AbhaySingh-dd9xc
      @AbhaySingh-dd9xc 3 года назад

      @@CodeWithHarry harry bahii bilkul right

  • @khatariinsaan5284
    @khatariinsaan5284 2 года назад

    Mai aap logo se promise karta hu ke
    mai aap logo to *promise* acche tarike se batunga
    What a way to teach 😂😍

  • @sugandhaparasher8861
    @sugandhaparasher8861 3 года назад

    Super Dost... very well explained

  • @Ertyuiigff-sq5fi
    @Ertyuiigff-sq5fi 2 года назад

    superb video

  • @ashpreetsinghanand7260
    @ashpreetsinghanand7260 2 года назад +1

    function f2(){
    return new Promise((resolve,reject)=> {
    setTimeout(() =>{
    let flag=true;
    if(flag==true){resolve();}
    else{reject();}
    }, 2000};
    });
    }
    f2.then(()=>{console.log("no error from API");}).catch(()=>{console.log("error");})

  • @163_sakshimalage5
    @163_sakshimalage5 2 года назад

    Please make video on Pyodide

  • @abhijitbarman4401
    @abhijitbarman4401 4 года назад

    Harry bhai apne promise pura kardia!