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
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
Check it now day he is explained those concept from Namaste 🙏 JS ❤️❤️❤️❤️
Absolutely ridiculous how most explanations out there make it seem so complex, yet you nailed it on the first try. Great video !!
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!!!
Ok now my decorator concept is clear too😅😅
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
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.
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.
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
Thank you so much, @Srujana. This comment means a lot. ❤️
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.
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! 💘 💘
implement sum of two numbers in currying is a question asked in PAYTM. Thankyou for the video its simply amazing :).
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...
you are the best on youtube, no one can beat you. Thanku so much for your information.
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!
because of you akshay i am fall in love with js, your explanation is very amazing.
your patience is himalayas brother..
thankyou for letting all these noobs on board..
nice and clear explanation,kepp doing we need it
I understood the currying in such a way that I won't look any other video for this concept. Thank you @Akshay Saini
I watch your videos regularly. You explain a concept but you don't explain its practical use which makes your lessons incomplete.
Your concepts are more simplified. Whenever I was seeing JS.... It felt like headache.... Thanks Sir....
incisive and clear explanations :))))
bro. You are very excellent tutor
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.😲
yet another good tutorial, concise and clearly explained.
Really greatt explanation of each topic of JavaScript
Why are you not continuing this Front end Interview question series? This is pure Gold. All the videos.
Now we have it as a part of new video series, "Namaste JavaScript" - ruclips.net/p/PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP
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.
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
What I think could be the use case is where you want to work with different combinations of dynamic Data.
Thanks a lot to implement currying using a bind method!
Very nicely explained..!!
I wish i had some entire js course from scratch to pro in js from this person only..!!
Now we have it, "Namaste JavaScript" - ruclips.net/p/PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP
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
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.
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. :)
@@akshaymarch7 I meant this only. Please add the code when you get time. :)
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.
Excellent explanation take a bow
concise and simple explanation
Hey ! Thanks for explaining function currying
Awesome explanation +++++++++++++++++++ Thank You
Thumps up from Nepal !
Thanks bhaiya for making such useful videos
Excellent video
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.
great knowledge i ever seen in javascript tutorial. good work ;)
You are great
you are quite good teacher
Got it.... Thank you man!👍👏👏👏
Very precised and get to learn in the whole video
You are awesome 😎😎😎😎
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
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.
THANK YOU SO MUCH
great video 100%
Hey Akshay, very good session. thanks a lot
I think this is begginer stage well explained but mood not 🔥
But now in namshate javascript Akshay mood is 🔥🔥🔥🔥🔥
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.
Hi Akshay,
Thanks for the best explanation. Nice work.
Awesome explanation
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.
Can you prepare a better sequence for this playlist and send it to me. I'll do that. 🙏
totally on point!
Hi, I just love your way of explanation. Could you please explain Partial Application as well and the difference between currying and partial application?
@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.
Even your small explanation makes concept very clear. Loved your knowledge and teaching skills.
Thank you, your videos are so helpful.
I am preparing for the UI full stack developer. Please help by making some more important questions asked in interview for the same.
just a small request Hey Akshay please try to explain with real life scenario where these concept is useful,
great video A big thank you!
Greate Explanation... can you do something for Generator function.
Hi Akshay you explained concept so well .It can related and easy to grasp ,thanks a lot :)
Thank you for teaching us 🙏
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.
It's great to know Shivang, keep practicing you'll become better. All the best 😊👍
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.
After namste javascript we are here😂
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.
Thx,finally I understood .
Closures do have the super power.
they REMEMBER.
You should also explained about multiply(1)(2)(3) which is the main use case of function currying
const multiply = function (x) {
return function (y) {
return function (z) {
return console.log(x * y * z);
};
};
};
multiply(1)(2)(3);
output -> 6
nice and thanks...
awesome
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.
Now we have it as a part of new video series, "Namaste JavaScript" - ruclips.net/p/PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP
@@akshaymarch7 Yes 😁 I am already following those sessions. Thanks
What is the use of curring function and any practical example of u provide will be good.
Hi Akashy ,
I am a big fan of you
Please can you make YT videos related to Data engineer and Data science
Nice vlogs brother, but i would suggest, you should also mention the benefits of the functions/methodology or why are we using this.
Thanks keep updating.
can you make the video about some rxjs opeartors and explain what happens behind the scenes in those operator.
Could you explain where exactly in real-life we are using this currying concept ?
great, plz also make polyfill for call and apply
Can you tell about shadow dom and rest api and soap model with a clear example. Thanks for your videos really helpful
Hey Akshay!.
your explaining technique is quite good. can you please make a video on Arrow function ()=>{} .
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 .
It's really helpful. Can u please make video of generator function in js?
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"
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
You can add what currying is , in this video alike you explained in closure 😇 some interviewer ask theatrical definition 😅
so basically function currying can be implemented two ways.
1: with help of closures & higher-order functions
2: With bind method
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.
Hey Ashutosh, I already have a playlist where I am covering important JS Interview Questions. Please checkout those videos on the channel.
so here what is the use of this keyword while doing the currying using bind method bro? why we are passing it
I’m learning core concept of js. Need more info about when what to use function curry or closure ?
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?
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
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.
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
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.
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?
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?
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.
Please make a video on promises
Hi Akshay
Please can you cover react and redux tutorials.