🔴 Get my Complete Frontend Interview Prep course - roadsidecoder.com/course-details ➡ Book an Interview Preparation call with me ( 20% OFF for limited time ) - topmate.io/roadsidecoder 🟪 Follow me on Instagram and u will clear your interview 🤓 - instagram.com/roadsidecoder/
Great content, i recently gave a interview in cleartrip they asked this 4 question 1) write polyfill for promise 2)deep comparison of object 3) polyfill for call, apply,bind 4) polyfill for map, reduce,filter, forEach. It's help me and others if you can cover this questions
Bro thanks for sharing such knowledge in your videos but at the same time you need to make sure you are doing it right as so many people are watching these content , here in memoise polyfill your code is mistaken Json.stringyfy(...args) will not return us "500,500" in res object instead it will just jive us the first value of the array as we are not iterating the args array therefore even if we pass (500,500) and (500,600) as args we will get the same result and in the second function call res will mark the args as present in the object already, so to avoid we can do argsCache = args.join(",") then it will store in the res object as explained in the video by the way thanks for your content. happy coding to all
Videos are good. But one suggesting instead of asking us to refer ur previous video just explain the functionality in one line & it will be much much helpful...
Thankyou for this knowledge packed closures' video Pyiush. It is the most detailed video I found on RU-vid and it covers all the important questons. Please make more of such content 🖖👍👌
Hi RoadsideCoder, great lessons, your explanations are very clear, thank you for all this work! I still have a question about "Question 8 - Once Polyfill Implementation" You pass a "context" argument and then apply it to the function, but I don't quite understand in which cases it would be useful? In your example "this, arguments" are applied, and everything would work even if we delete "context" from the code. When is it useful to pass a "context" and what kind of data is expected for this argument?
"At 22:51, wouldn't creating the inner function inside the loop lead to a new function being created in memory every time? I think a better approach would be to define the function outside the loop, so it's created only once. This way, the function can be reused, which is more efficient." function print(num) { setTimeout(()=>{ console.log(num) },num * 1000) } for(var i = 0;i
Hey Piyush that Time Optimisation part was something new that I learnt today 16:20. Can you explain the the exact reason what closures did such that it took less time to execute the function
please add some algorithm questions and class / constructor functions question which are often ask in interviews. for example: implement a MinStack. By the way, a friend of mine got the setTimeout with var and let question in his last interview.
case 1 : function x(){ var a = 7; function y(){ console.log(a); var a = 5; } y(); }; x(); output : undefined case 2 : function x(){ var a = 7; function y(){ console.log(a); } y(); }; x(); output : 7 case 3 : function x(){ var a = 7; function y(){ var a = 5; console.log(a); } y(); }; x(); output : 5
what will happen if we create simultaneously two function inside of a function?? like :- function a() { function b() { return "this is clouser or not?"; } function c() { return "is this a closure also ?"; } }
wouldn't the function function likeTheVideo(){ if(view !=undefined){ return; } view = 'dave' console.log("subscribe to ",view) } would also allow soolve problem 7 ? Awesome video btw
Hi Piyush, As per Ques no. 1 on line number 6 if (count ===0) so count is taking value from outer scope variable , but in below case it is throwing error : VM654:3 Uncaught ReferenceError: Cannot access 'x' before initialization at abc (:3:17) at :7:1 let x = 9 function abc(){ console.log(x); // It should print 9 as in Ques no. 1 count was accessing value from outer scope which is global let x = 5; console.log(x); } abc(); Please explain
Dood it's because of let and const is in temporal dead zone, If condition only executes it's respective code in it's block since let/const has block scope, In his example, count was not there in the function block it' was inside if block. but for your case since there's no block, It first check abc's scope while executing the code, so in the execution context it will first store x in temporal deadzone, so you have to initialize before accessing, Hope this answers your question
@Roadsidecoder For the time optimization without using closure part , as i give higher number time taken is less, any idea why is this happening? function find(index) { let a=[]; for(let i=0;i
In the once polyfill, can we use call instead of apply? If yes then how? Also you are modifying function param to null right, won't that cause any issues?
Nice video but you did not explain why the time got reduced in the time optimization question… because of this still I have no clarity of the use of closures… can you please reply??? also I saw that you don’t even replies to your subscribers comments… please start replying
In the previous `find` function the loop which filled the array runs a million times on each call. So when you called it twice, first for number 6 and then second for number 12, the loop ran twice for total of 2 million. Basically the loop was running on every call. The optimized `find` function ran the loop once and then returned a function which will just log out the array index value. So when the host run `const closure = find();`, the loop runs and an array is created and a function is returned which is stored in `closure` variable. Now when you use closure variable like `closure(6)` or `closure(12)`, the loop won't run as it has already run and the filled array is referenced to closure function via the concept of closures. So you may run the function 10 times the loop will run only a million times contrasting the previous function which would have ran 10 * million times. Feel free to ask a follow up.
In the question at 27.40 i.e question no 7, the functionality which you wanted is easily acheived by the below code, let view = 'Roadside Coder '; let num = 0; const singleFunction = ()=>{ if(num > 0){ console.log('already Subscribed') } else { console.log('subscribe to' + view) num++ } } what is the difference between the code which you wrote and the above code? In my approach, I didn't had to create inner function.
You can do that as well as you have created a global counter but in video the counter is a local variable. Every time you call that function, the counter will be 0 this is why closure is used to store the reference of previous count
Question 7: Make this run only once We can also write like this. Is that make sense? @RoadSideCoder Brother I'm waiting for your reply let called = false; function likeTheVideo() { if(called === false) { console.log('First time we are calling') called = true } else { console.log('Already we are called') } } likeTheVideo() likeTheVideo() likeTheVideo() likeTheVideo() likeTheVideo() likeTheVideo() likeTheVideo() likeTheVideo() likeTheVideo()
For those of you wondering how to fix the var scope issue with closure. const c = () => { for(var i =0; i < 3; i++){ ((i) =>{ setTimeout(() => { console.log(i); },1000); })(i); } } c();
function Namedis(){ var name="aksuman"; } Namedis() console.log(name) iam doing same thing but i am not getting error with this why?? unable to find answer plz help