Currying in Javascript | JS Interview Questions

Поделиться
HTML-код
  • Опубликовано: 6 фев 2025
  • Function Currying is a cool feature of functional programming with Javascript. This video covers two ways to achieve that, firstly by using bind function and the second using the concept of closure.
    Currying refers to the process of transforming a function with multiple arity into the same function with less arity. The curried effect is achieved by binding some of the arguments to the first function invoke, so that those values are fixed for the next invocation.
    If you get to learn something from this video then do give it a thumbs up and subscribe to this channel for regular awesome videos.
    If you find my videos helpful,
    then please support this channel by buying a coffee,
    www.buymeacoff...
    Cheers,
    Akshay Saini
    akshaysaini.in
    Would love to Stay Connected with you ❤️
    LinkedIn - / akshaymarch7
    Instagram - / akshaymarch7
    Twitter - / akshaymarch7
    Facebook - / akshaymarch7
    #Javascript #JavascriptInterviewQuestions #AkshaySaini

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

  • @singlapriyanka97
    @singlapriyanka97 4 года назад +63

    Hey Akshay!
    Concise and precise explanation, really. I am finally able to understand some core JS concepts.
    Please please make a video on Closures and Lexical Scoping. This seems to be a hot topic in many JS interviews and have been struggling to find a good explanation on these particular topic. I totally understand and able to connect the dots with your explanation. Cheers! Looking forward for some more videos super soon :D

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

      Check it now day he is explained those concept from Namaste 🙏 JS ❤️❤️❤️❤️

  • @kalaiselvamg9884
    @kalaiselvamg9884 3 года назад +7

    Absolutely ridiculous how most explanations out there make it seem so complex, yet you nailed it on the first try. Great video !!

  • @0xFOXHOUND
    @0xFOXHOUND 4 года назад +19

    For Revision
    Function currying
    1) Bind method,
    Take a function, modify it by attaching bind to define a parameter (or method)
    2) Closure method
    Take a function, Define parameter in closure style, define another parameter by just defining it while using as curried version
    {In python for achieving similar functionality Somewhat similar method is used, called as "Decorators"}
    Superb explanation Sir!!!

  • @jitendersingh6906
    @jitendersingh6906 3 года назад +13

    Like one has a craze to complete web series these days in a single day, after watching your tutorial from Namaste JS, I am crazy to see each video of your channel, thanks for such great knowledge

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

    Only yesterday, I was interviewed and was asked the question "What is closure and where it is used?". I had given the page-hit-counter as an example of a closure usage. Now I know what is another usage. Thanks for the valuable posted.

  • @Starboy_Sandy03
    @Starboy_Sandy03 11 месяцев назад +1

    The video explains two ways to achieve function currying in JavaScript - through the use of bind functions and through closures. Currying allows for creating multiple versions of a function by pre-setting some of its arguments.
    [00:00](ruclips.net/video/vQcCNpuaJO8/видео.html) This section introduces the concept of function currying in JavaScript using bind method.
    - Function currying can be achieved in JavaScript using bind functions and closures.
    - The bind method is used to create a copy of a function with preset arguments.
    - The copied function can be invoked later with the remaining arguments.
    - The bind method sets the preset arguments as the initial values of the copied function's parameters.
    [02:04](ruclips.net/video/vQcCNpuaJO8/видео.html) Function currying in JavaScript allows us to create copies of a function with predefined arguments.
    - By passing an argument to the curried function, it behaves as if the argument was the first parameter.
    - Currying can be done for any number of arguments.
    - The bind method is used to create curried functions in JavaScript.
    [04:08](ruclips.net/video/vQcCNpuaJO8/видео.html) Currying in JavaScript allows us to create new functions with pre-set arguments using either method chaining or function closures.
    - Method chaining involves creating new methods by pre-setting arguments inside the function.
    - Function closures involve returning a new function that has access to pre-set arguments even after it's returned.
    - Currying allows for more flexibility and reusability in code.
    [06:12](ruclips.net/video/vQcCNpuaJO8/видео.html) The video explains two ways to implement function currying in JavaScript: using the bind method and using closures.
    - One way to implement currying is by using the bind method.
    - Another way to implement currying is by using closures.
    - The video demonstrates creating a multiply by 3 function using the closure concept.
    - The video concludes by encouraging viewers to give feedback and suggesting future topics for the channel.

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

    I feel mind blown watching your videos.. all my UI years I was scared of such trivial details, thank you and please continue sharing gyaan like this

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

      Thank you so much, @Srujana. This comment means a lot. ❤️

  • @aanavdiaries5170
    @aanavdiaries5170 4 года назад +32

    Hi Akshay, please add use cases of concepts , like why should we use it and where should we use it . It will help us more to relate.

  • @kirubakaransrinivasan8338
    @kirubakaransrinivasan8338 5 лет назад +21

    Hey Akshay,
    Thanks for spending time to share what you have learnt. The person who knows the pain of learnings something without a teacher. I could see that from your teaching!
    The way you understood the concepts are really deep, i could see that when you teach it.
    Excellent job, keep going! 💘 💘

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

    implement sum of two numbers in currying is a question asked in PAYTM. Thankyou for the video its simply amazing :).

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

    I have always ignored JS, thinking it is weird to type and learn. But two things motivated me. 1. Your tutorials.Especially they are byte sized. 2. The craze of the JS in the tech world. Even if you know more complicated frameworks like Android, iOS it is just not enough. It is complete only with JS. One request from me, it would be great if you can wrap up the video with a mention of real time use case of the concept. Thank You...keep doing more...

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

    you are the best on youtube, no one can beat you. Thanku so much for your information.

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

    Whenever I have any concern in any topic I search particular topic and Akshay name, if there is any video, That's it I won't try to find any other video. You teaches me so well, that topic just stick to my brain. and fun part is i have not even start this video. i know its gonna be very explanatory. Kudos to you man!

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

    because of you akshay i am fall in love with js, your explanation is very amazing.

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

    your patience is himalayas brother..
    thankyou for letting all these noobs on board..

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

    nice and clear explanation,kepp doing we need it

  • @bhanukiran5089
    @bhanukiran5089 9 месяцев назад

    I understood the currying in such a way that I won't look any other video for this concept. Thank you @Akshay Saini

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

    I watch your videos regularly. You explain a concept but you don't explain its practical use which makes your lessons incomplete.

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

    Your concepts are more simplified. Whenever I was seeing JS.... It felt like headache.... Thanks Sir....

  • @priyaarya6883
    @priyaarya6883 5 месяцев назад +1

    incisive and clear explanations :))))

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

    bro. You are very excellent tutor

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

    Akshay, did anyone tell you that this is a masterpiece? Search no further...This indeed is way brilliant of you. I knew about closures but i did not get to understand it this way.😲

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

    yet another good tutorial, concise and clearly explained.

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

    Really greatt explanation of each topic of JavaScript

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

    Why are you not continuing this Front end Interview question series? This is pure Gold. All the videos.

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

      Now we have it as a part of new video series, "Namaste JavaScript" - ruclips.net/p/PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP

  • @Paras-Mahto
    @Paras-Mahto 5 лет назад +11

    Hello Akshay..
    Can you please cover all the topics of ES6 features with example.. It will be very helpful to us. The way you Explain and TEACHING the stuff is awesome in camera.

  • @chetanrathod4780
    @chetanrathod4780 4 года назад +13

    The content is good, but after saw your video I have to Google Search the things to deep dive, and then I have to struggle to understand so can you please add in your every video that why to use this functionality. It will helpful for everyone

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

      What I think could be the use case is where you want to work with different combinations of dynamic Data.

  • @SowmyaS-n6e
    @SowmyaS-n6e Год назад

    Thanks a lot to implement currying using a bind method!

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

    Very nicely explained..!!
    I wish i had some entire js course from scratch to pro in js from this person only..!!

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

      Now we have it, "Namaste JavaScript" - ruclips.net/p/PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP

  • @MayankSingh-nk7xj
    @MayankSingh-nk7xj 5 лет назад +1

    Sir please aap js pe complete series banaye.. Maine bahut se videos dekhe but aisa conceptualised
    Explanation khi nahi mila.. Thanku for making it easy

  • @TheNerdyDev
    @TheNerdyDev 6 лет назад +2

    The returned function is inside the lexical environment of the multiply function so it can access the preset variable x that we get from outside multiply function. Correct me if I am wrong and Thanks a lot sir.

    • @akshaymarch7
      @akshaymarch7  6 лет назад

      Which part of the video are you referring to? Let me know it clearly. However, according to closures, the returned function has access to the variables which are passed as a reference to the parent function. Hope this clears your doubt. :)

    • @TheNerdyDev
      @TheNerdyDev 6 лет назад +1

      @@akshaymarch7 I meant this only. Please add the code when you get time. :)

    • @akshaymarch7
      @akshaymarch7  6 лет назад +1

      Added for Debouncing, Event Bubbling, Capturing and Polyfill for Bind in the respective video description. Will add for others also and will make sure that I save the code while recording the video next time and add the link right while publishing.

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

    Excellent explanation take a bow

  • @jokerlast-l7d
    @jokerlast-l7d Год назад

    concise and simple explanation

  • @jalluchakri1528
    @jalluchakri1528 5 месяцев назад

    Hey ! Thanks for explaining function currying

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

    Awesome explanation +++++++++++++++++++ Thank You

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

    Thumps up from Nepal !

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

    Thanks bhaiya for making such useful videos

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

    Excellent video

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

    Hey Akshay, your explanation on any topic will be very clear, can you please make part 2 for currying how and where it can be used efficiently.

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

    great knowledge i ever seen in javascript tutorial. good work ;)

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

    You are great

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

    you are quite good teacher

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

    Got it.... Thank you man!👍👏👏👏

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

    Very precised and get to learn in the whole video

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

    You are awesome 😎😎😎😎

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

    Hey Akshay,
    your videos are very deep and detailed. Recently I watched your Namaste JavaScript Series and it was just mind blowing, I got to know so much new things.
    Thanks a lot

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

    What is the currying function
    Currying is the process of taking a function with multiple arguments and
    turning it into a sequence of functions each with only a single argument.
    Currying is named after a mathematician Haskell Curry. By applying
    currying, a n-ary function turns it into a unary function.
    19Let’s take an example of n-ary function and how it turns into a currying
    function,
    const multiArgFunction = (a, b, c) => a + b + c;
    console.log(multiArgFunction(1, 2, 3)); // 6
    const curryUnaryFunction = (a) => (b) => (c) => a + b + c;
    curryUnaryFunction(1); // returns a function: b => c => 1 + b + c
    curryUnaryFunction(1)(2); // returns a function: c => 3 + c
    curryUnaryFunction(1)(2)(3); // returns the number 6
    Curried functions are great to improve code reusability and functional
    composition.

  • @puja-z6c
    @puja-z6c 7 месяцев назад +1

    THANK YOU SO MUCH

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

    great video 100%

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

    Hey Akshay, very good session. thanks a lot

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

    I think this is begginer stage well explained but mood not 🔥
    But now in namshate javascript Akshay mood is 🔥🔥🔥🔥🔥

  • @heena6814
    @heena6814 Год назад +1

    Hi Akshay, Thank You so much for awesome explanation. Can you please mention the sequence also as there are multiple playlist in your channel. It is little confusing which series we need to check first as there are some topics which are interlinked with each other.

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

    Hi Akshay,
    Thanks for the best explanation. Nice work.

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

    Awesome explanation

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

    Please put videos in a sequence in playlist, like call, apply and bind method video on top of polyfill video and so on. Otherwise your videos are so easy to understand and crystal clear.

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

      Can you prepare a better sequence for this playlist and send it to me. I'll do that. 🙏

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

    totally on point!

  • @02sonali
    @02sonali 4 года назад +2

    Hi, I just love your way of explanation. Could you please explain Partial Application as well and the difference between currying and partial application?

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

    @2:43 you mention that the value passed in would be y. Just to clarify the value passed in to multiplyByTwo(5) the 5 will = y because in the bind we have already specified binds first 2 arguments which is (this, 2) so the third thing passed in would be like a 3rd arg that then multiply function would take in as well.

  • @akashsingh-ch5xc
    @akashsingh-ch5xc 4 года назад +1

    Even your small explanation makes concept very clear. Loved your knowledge and teaching skills.

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

    Thank you, your videos are so helpful.

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

      I am preparing for the UI full stack developer. Please help by making some more important questions asked in interview for the same.

  • @AKASHKUMAR-we5hg
    @AKASHKUMAR-we5hg 4 года назад +1

    just a small request Hey Akshay please try to explain with real life scenario where these concept is useful,

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

    great video A big thank you!

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

    Greate Explanation... can you do something for Generator function.

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

    Hi Akshay you explained concept so well .It can related and easy to grasp ,thanks a lot :)

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

    Thank you for teaching us 🙏

  • @shivangranjan1389
    @shivangranjan1389 6 лет назад +4

    This is awesome bhaiya! Have been working with javascript and feel there is still a lot to cover! This initiative of yours will help us a lot. Btw, I am also studying @ your undergrad school.

    • @akshaymarch7
      @akshaymarch7  6 лет назад +1

      It's great to know Shivang, keep practicing you'll become better. All the best 😊👍

  • @devendrasuthar5530
    @devendrasuthar5530 10 месяцев назад

    Hey this is what you will sound like if you don't go deep into the topics as you have gone in namste javascript It was hard to understand bind function implementation. In previous video I hope you will teach these concept again.

  • @Rajveer__singhhhh
    @Rajveer__singhhhh Год назад +2

    After namste javascript we are here😂

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

    It would help a lot if you could create a fully fledged project involving all these concepts so as to highlight there usage in the process of development. Thank you. Great video once again.

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

    Thx,finally I understood .

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

    Closures do have the super power.
    they REMEMBER.

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

    You should also explained about multiply(1)(2)(3) which is the main use case of function currying

    • @ironman-29
      @ironman-29 Год назад +1

      const multiply = function (x) {
      return function (y) {
      return function (z) {
      return console.log(x * y * z);
      };
      };
      };
      multiply(1)(2)(3);
      output -> 6

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

    nice and thanks...

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

    awesome

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

    Hey Akshay, your videos really works. I am practicing parallel in editor as code is to be written not remembered. Just waiting for Closures tutorial.

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

      Now we have it as a part of new video series, "Namaste JavaScript" - ruclips.net/p/PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP

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

      @@akshaymarch7 Yes 😁 I am already following those sessions. Thanks

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

    What is the use of curring function and any practical example of u provide will be good.

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

    Hi Akashy ,
    I am a big fan of you
    Please can you make YT videos related to Data engineer and Data science

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

    Nice vlogs brother, but i would suggest, you should also mention the benefits of the functions/methodology or why are we using this.

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

    Thanks keep updating.

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

    can you make the video about some rxjs opeartors and explain what happens behind the scenes in those operator.

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

    Could you explain where exactly in real-life we are using this currying concept ?

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

    great, plz also make polyfill for call and apply

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

    Can you tell about shadow dom and rest api and soap model with a clear example. Thanks for your videos really helpful

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

    Hey Akshay!.
    your explaining technique is quite good. can you please make a video on Arrow function ()=>{} .

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

    Nice explanation in the sort. But could you please explore in the videos of why use and why need of this function in the java script .

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

    It's really helpful. Can u please make video of generator function in js?

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

    a bit different with strings - prints first params in bind, ignores call param if over limit
    let print = function(first, second) {
    console.log(first + ' '+ second)
    };
    let call1 = print.bind(this, "one");
    call1("two");
    let call2 = print.bind(this, "three", "four");
    call2("two");
    let call3 = print.bind(this, "three", "four", "five");
    call3("two");
    OUTPUT >
    "one two"
    "three four"
    "three four"

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

    Hi Akshay Nice video I am checking on web the concept currying if there is any function multiply (3)(2)(4); what it's mean it is a closure or what? Please explain

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

    You can add what currying is , in this video alike you explained in closure 😇 some interviewer ask theatrical definition 😅

  • @Mr.Zeus11
    @Mr.Zeus11 10 месяцев назад

    so basically function currying can be implemented two ways.
    1: with help of closures & higher-order functions
    2: With bind method

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

    the video was good but Can you also solve one of the most frequently/important questions asked for that particular topic to have a better understanding and also it will also give an idea of the use cases.

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

      Hey Ashutosh, I already have a playlist where I am covering important JS Interview Questions. Please checkout those videos on the channel.

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

    so here what is the use of this keyword while doing the currying using bind method bro? why we are passing it

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

    I’m learning core concept of js. Need more info about when what to use function curry or closure ?

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

    Can you please explain how the bind function is used for achieving currying?
    Currying is a transformation of a function with multiple arguments into a sequence of nested functions with a single argument.
    Bind takes two arguments which are reference object and value, with the copy variable second method is called. Can the bind method used for nested functions that accepts single arguments?

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

    your concept is good....can u make video on ECMAScript6 and its all feature and function....i m sure you will get best suscription...i m seeing many javascript video .....but your video are awesome in javascript....please make more video and i will tell my friend to subscribe

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

      First of all thanks a lot for the nice words. Glad to know that you like the videos. But one doubt, isn't there already so much good content available regarding ES6 on RUclips. Doesn't that help? I'm trying to cover topics which aren't explained properly and people struggle with them.
      But thanks for suggesting, I've noted it down anyways, will try to cover that as well ASAP.

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

    Hi Akshay , when we set the argument using bind say bind(this, 3), this way of presetting the arguments isn't called partial() ? I am confused with partial and curry

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

      Hope this blog post will give a clear understanding of partial and curry functions blog.bitsrc.io/understanding-currying-in-javascript-ceb2188c339. As per this post, the bind(this,3)(10) is a currying function as a single argument is passed at a time.

  • @romaghosh8649
    @romaghosh8649 6 месяцев назад

    when we can easily perform the same operation using closures then why do we use bind? do we ahve any specific conditions where to use bind and where to use closures for function currying?

    • @romaghosh8649
      @romaghosh8649 6 месяцев назад

      one more question is like when we can directly call a function and pass values in it and the result then why do we use bind method or function currying?

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

    Please do a video on generator functions and how they execute. i got a interview question from a product base company but not sure about my answer.

  • @shreenidhim.r9925
    @shreenidhim.r9925 3 года назад

    Please make a video on promises

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

    Hi Akshay
    Please can you cover react and redux tutorials.