1:25:42 - I almost spent 10 minutes trying to figure out why he is using func.length >= args.length, only to realise a few seconds later he fixed the bug. Typically viewers might be actively thinking as you speak and such bugs can cause confusions, so I would humbly request processing the video beforehand to avoid such confusions.
Thanks a lot man, I had watched this video a day before my interview and some of the interview questions were exactly the same , and I was able to successfully clear the interview in a really good product based company 😊
45:45 function a() { for (var i = 0; i < 3; i++) { (function(i) { setTimeout(function log() { console.log(i); }, i * 1000); })(i); // Pass the current value of `i` to the IIFE } } a(); Since each iteration has its own IIFE with its own scope, each setTimeout callback retains the correct i value.
Here is an alternate explanation for "setTimeout + blockscope": "a" contains a for loop that iterates three times. Inside the loop, a setTimeout function is called for each iteration, with a delay that increases with each iteration (0, 1000, 2000 milliseconds). However, the callback function inside the setTimeout refers to the variable i, which is declared using var. Since var does not have block scope, the final value of i after the loop completes is 3.
For the evaluate function at 1:12:43, a switch conditional would be cleaner: function evaluate(operation) { return function (a) { return function (b) { switch (operation) { case "sum": return a + b; case "multiply": return a * b; case "divide": return a / b; case "subtract": return a - b; default: return "Invalid Operation"; } }; }; }
Piyush I found this video when I had 24 hours to prepare for a technical interview to test javascript proficiency. I have to tell you how much I appreciate your interview prep video because it seems I had forgotten many things. Honestly, some topics were never made so clear for me - you're a great teacher. I'll follow up here once I finish the interview, but I definitely owe you a coffee ! thank you
41:01 Both approaches should give almost constant value (the first approach is longer and the closure one is short). There is no async involved in the process, and we will run the large for loop either way no matter what is the input value. The reason closure is faster is not because there is any magic in it, but just you run the closure() before the counting and it is like a cache, storing the calculated array in the function scope. Let me know if my understanding is correct, otherwise, it does not make sense to me
You are correct. The optimization comes into play when you need to call the anonymous() function multiple times with different indices. Without memoization, each call to find() would recompute the entire array on every invocation, resulting in significant overhead. By using memoization, you ensure that the array is computed only once and subsequent calls utilize the precomputed array, reducing redundant computations and improving performance.
Another solution for ques 6 at 1:23:01 -> "const curry = f => a => b => c => f(a, b, c)" expanded code for clarity function curry (f) { function layer1(a){ function layer2(b){ function layer3(c) { return f(a, b, c) } return layer3 } return layer2 } return layer1 }
I do like the way you explained it, and tried to keep the code simple and minimalistic to avoid confusion. This especially helps when you are exploring a complex concept. Apart from once function I was almost able to understand all, also in one go with small breaks,so the video was interesting enough to keep me attentive including some minor drink and stretch breaks. This is indeed a great valued content worth every single second of my watchtime but hey, we don't count in seconds , right? :) TLDR : Great content. Good luck for future ones, and this one helped a lot.
Dude i appreiacate you took the time to explain these questions but half why you directed us to "here's another video for this" , "here's another video for this", i wish you would have explained everything in this video like you mentioned in the start...
I will pray for you to get the job when I sleep and when I am in the bus 🚌. Good Luck. i am going to travel in a 6 hours trip by bus with my mother to meet my sister and brother because of eid.
41:01 I still not using closure but i get the same performance boost :) function find(index) { let a = []; for (let i = 0; i < 10000000; i++) { a[i] = i * i; } console.log(a[index]); return function () {}; } const closure = find(12); console.time("12"); closure(); console.timeEnd("12");
41:01 - Should it not take the same time in the non optimised implementation because the loop would run the same number of times irrespective of the index passed?
the loop runs when the function is assigned (`const closure = find()`) - the variable `a` is then stored inside the newly created local scope and calling `closure(n)` only needs to read the value from the precomputed array
@@kuubeu You did not understand the question which I asked, never mind. The non-optimized was not optimal because there was no precomputation, and hence in every invocation the array was created again and again, and that would be time-consuming. And optimizing in this context meant pre-computing so that the time to construct the array, again and again, is saved. However, if you do notice the code carefully in both versions, the size of the constructed array is the same ( 1000000 or 1 million ) and hence the time taken to construct the array should be the same theoretically be it in an optimal and sub-optimal version.
@@pranavbhat29 it does take the same amount of time if you run it only once, after that it's basically instant: unoptimized: find(a) // takes long find(b) // also takes long // ... all slow optimized: const closure = find() // takes long closure(a) // very fast closure(b) // very fast // ... all fast
Some one explain how this is working function once(func, context) { let ran; return function() { if(func) { ran = func.apply(context || this, arguments) console.log("ssss", ran) func = null } return ran } } what does ran contains after running and how the function reinitialized to null?
- Depends on the return value of the func. As per the example in the video, func is console.log and returns undefined. So, ran will have a value of undefined. When the inner anonymous function is called for the first time, func is assigned a value of null. Then after that when anonymous function is called again, func will value null. So, it will not enter the if block.
You can cut the code by using keyboard shortcut ctrl + x, ctrl + v or use VS code shortcut by selecting text, holding alt key then moving it up and down with arrow keys.
The stock market's dividends motivated me to start investing. What counts, in my opinion, is that you will be able to live off of dividends without selling if you invest and make more money in addition to payouts. It suggests that you can give your children that advantage, giving them a head start in life. I've invested more than $600k throughout the years in dividend stocks; I'm still buying more today and will keep doing so until the price drops even further.
It's always inspiring to hear from a veteran investor who has weathered the storm and come out on top. When your portfolio turns from green to red, it might be unsettling, but if you have invested in great companies, you should just keep adding to them and stick with your plan.
I wholeheartedly concur, which is why I appreciate giving an investment coach the power of decision-making. Given their specialized expertise and education, as well as the fact that each and every one of their skills is centered on harnessing risk for its asymmetrical potential and controlling it as a buffer against certain unfavorable developments, it is practically impossible for them to underperform. I have made over 1.5 million dollars working with an investment coach for more than two years.
There are many financial coaches who excel in their profession, but for the time being, I employ "Jackson Sten Marsh," because I adore his methods. You can make research and find out more.
Bro literally saved my life today, I watched this video before the interview, It went excellent.
did you get the job?
@@Antonailzb Yes bro, I started 3 months ago here.
@@mayursmahajan congrats bro! hope its been good to you
1:25:42 - I almost spent 10 minutes trying to figure out why he is using func.length >= args.length, only to realise a few seconds later he fixed the bug. Typically viewers might be actively thinking as you speak and such bugs can cause confusions, so I would humbly request processing the video beforehand to avoid such confusions.
Thanks a lot man, I had watched this video a day before my interview and some of the interview questions were exactly the same , and I was able to successfully clear the interview in a really good product based company 😊
Were you hired?
Yes😊
which company brother?@@abhishekmohanty232
Great course, from basic to advanced questions.
45:45
function a() {
for (var i = 0; i < 3; i++) {
(function(i) {
setTimeout(function log() {
console.log(i);
}, i * 1000);
})(i); // Pass the current value of `i` to the IIFE
}
}
a();
Since each iteration has its own IIFE with its own scope, each setTimeout callback retains the correct i value.
Here is an alternate explanation for "setTimeout + blockscope":
"a" contains a for loop that iterates three times. Inside the loop, a setTimeout function is called for each iteration, with a delay that increases with each iteration (0, 1000, 2000 milliseconds). However, the callback function inside the setTimeout refers to the variable i, which is declared using var. Since var does not have block scope, the final value of i after the loop completes is 3.
such an amazing content thank you so much! - a guy from the Philippines.
you explain so good! I am curious who is your employee. They are very lucky to have you.
For the evaluate function at 1:12:43, a switch conditional would be cleaner:
function evaluate(operation) {
return function (a) {
return function (b) {
switch (operation) {
case "sum":
return a + b;
case "multiply":
return a * b;
case "divide":
return a / b;
case "subtract":
return a - b;
default:
return "Invalid Operation";
}
};
};
}
Piyush I found this video when I had 24 hours to prepare for a technical interview to test javascript proficiency. I have to tell you how much I appreciate your interview prep video because it seems I had forgotten many things. Honestly, some topics were never made so clear for me - you're a great teacher. I'll follow up here once I finish the interview, but I definitely owe you a coffee ! thank you
Give us the update bro, we gotta know how that interview went...
Thanks ❤
41:01 Both approaches should give almost constant value (the first approach is longer and the closure one is short). There is no async involved in the process, and we will run the large for loop either way no matter what is the input value. The reason closure is faster is not because there is any magic in it, but just you run the closure() before the counting and it is like a cache, storing the calculated array in the function scope. Let me know if my understanding is correct, otherwise, it does not make sense to me
You are correct. The optimization comes into play when you need to call the anonymous() function multiple times with different indices. Without memoization, each call to find() would recompute the entire array on every invocation, resulting in significant overhead. By using memoization, you ensure that the array is computed only once and subsequent calls utilize the precomputed array, reducing redundant computations and improving performance.
This is such a good prep, but also entertaining somehow, first time watching stuff like this.
Another solution for ques 6 at 1:23:01 -> "const curry = f => a => b => c => f(a, b, c)"
expanded code for clarity
function curry (f) {
function layer1(a){
function layer2(b){
function layer3(c) {
return f(a, b, c)
}
return layer3
}
return layer2
}
return layer1
}
the manipulating DOM example does not seem to be of using currying, but more of using closure to store value of id.
Roadside coder is here🔥🔥
Explain?
his channel name @@AbhituklVerse
I do like the way you explained it, and tried to keep the code simple and minimalistic to avoid confusion. This especially helps when you are exploring a complex concept. Apart from once function I was almost able to understand all, also in one go with small breaks,so the video was interesting enough to keep me attentive including some minor drink and stretch breaks. This is indeed a great valued content worth every single second of my watchtime but hey, we don't count in seconds , right? :)
TLDR : Great content. Good luck for future ones, and this one helped a lot.
Dude i appreiacate you took the time to explain these questions but half why you directed us to "here's another video for this" , "here's another video for this", i wish you would have explained everything in this video like you mentioned in the start...
absolutely best timing, I have an interview tomorrow. thanks FCC !
whole vid be like "go and watch THAT vid"
Thank you so much for this video! Waiting for "this" video 😉
Thanks, You can check that video here - ruclips.net/video/rv7Q11KWmKU/видео.html
@@RoadsideCoder 👍👍
Excellent course, great video.
תודה!
17:30 Its Rest *Parameter* and Spread *Operator*
Fantastic video
You know the tutorial is going to be superior than others when the guy is Indian.
Treasure content.
Im already subscribed to his channel and love his content. ❤
35:24 is so confusing because on hoisting 14:26 with var the behavior is not the same...
Love the part on closures.
Was I simply too afraid? Should I start applying? Are these really expected interview questions for entry level?
i like the methods using shorthand syntax
its like making your naming of functions more reusable
Definitely needed this
This questions is very good for entry level js coding interview
Do a java job prep
I've interview tomorrow and this video came as blessing in disguise for me thank you @freecodecamp😊😊❤❤
I will pray for you to get the job when I sleep and when I am in the bus 🚌.
Good Luck.
i am going to travel in a 6 hours trip by bus with my mother to meet my sister and brother because of eid.
Did you pass your interview
Can you tell me about your interview experience?
He failed miserably … nobody learn coding by watch RUclips videos
@@abcproduction6819 No I didn't
thanks for this content will help me !
57:57 i though using apply() on arrow functions doesnt affect it?
Thanks for this! I'm saving this for when I'm ready for interviews.
41:01 I still not using closure but i get the same performance boost :)
function find(index) {
let a = [];
for (let i = 0; i < 10000000; i++) {
a[i] = i * i;
}
console.log(a[index]);
return function () {};
}
const closure = find(12);
console.time("12");
closure();
console.timeEnd("12");
Can a value can be shared between sibling functions in a function in closures
41:01 - Should it not take the same time in the non optimised implementation because the loop would run the same number of times irrespective of the index passed?
have the same question, no idea why the time is different
the loop runs when the function is assigned (`const closure = find()`) - the variable `a` is then stored inside the newly created local scope and calling `closure(n)` only needs to read the value from the precomputed array
@@kuubeu You did not understand the question which I asked, never mind. The non-optimized was not optimal because there was no precomputation, and hence in every invocation the array was created again and again, and that would be time-consuming. And optimizing in this context meant pre-computing so that the time to construct the array, again and again, is saved.
However, if you do notice the code carefully in both versions, the size of the constructed array is the same ( 1000000 or 1 million ) and hence the time taken to construct the array should be the same theoretically be it in an optimal and sub-optimal version.
@@pranavbhat29 it does take the same amount of time if you run it only once, after that it's basically instant:
unoptimized:
find(a) // takes long
find(b) // also takes long
// ... all slow
optimized:
const closure = find() // takes long
closure(a) // very fast
closure(b) // very fast
// ... all fast
@@kuubeu
In the video
unoptimized:
find(a) // takes t1 milliseconds
find(b) // takes t2 milliseconds
// and t1
🎉 nice
that's what i was waiting for 🏆 plss release more videos related to interview
the infinite currying is like recursion
Some one explain how this is working
function once(func, context) {
let ran;
return function() {
if(func) {
ran = func.apply(context || this, arguments)
console.log("ssss", ran)
func = null
}
return ran
}
}
what does ran contains after running and how the function reinitialized to null?
- Depends on the return value of the func. As per the example in the video, func is console.log and returns undefined.
So, ran will have a value of undefined.
When the inner anonymous function is called for the first time, func is assigned a value of null.
Then after that when anonymous function is called again, func will value null.
So, it will not enter the if block.
Java interview prep next😊
Awesome 👏
สวัสดีค่ะขอบคุณค่ะ❤😂🎉😢😮😅😊
Came in good time
Great❤
this closure thingy is huge stuff I just discovered today, thank you!
Life saviour
you were always referring to another video for another concept this video could have been good if all concepts were clear at the same time
shuru woh angrez kaun tha??
How did he move square() to console log? I mean what is she shortcut?
That's called a cut in the video, my guy
You can cut the code by using keyboard shortcut ctrl + x, ctrl + v or use VS code shortcut by selecting text, holding alt key then moving it up and down with arrow keys.
20:00 🔖
Thanks!
awesome!1
I understood nothing
1:23:00
❤
CURRYing
Racist
We need dart language
This video has lot of incorrect information, please correct the concept of closures if you could.
Can someone explain 9:10?
To understand that better, you need to understand scope of var, let and const. Just watch my var,let,const video!
Referenceerror: function not working
ReferenceError: argument is not valid
defined*
Could I cooperate with you on promotional video about software? Thanks
There's a joke somewhere to be made here about currying lol
Pdf de do
25:19
too much ads, every 3 minutes he advertised his product.
which product?
this video leads new programmers to terrible mistakes / I do not recommend
Could you elaborate on that?
Why do you need to yell? Do you think we are deaf?
hahahahahahahahaahahahahahahahaahahahahahahahahaahahahah
Dond dell me whad uoo duooo please 😅
The stock market's dividends motivated me to start investing. What counts, in my opinion, is that you will be able to live off of dividends without selling if you invest and make more money in addition to payouts. It suggests that you can give your children that advantage, giving them a head start in life. I've invested more than $600k throughout the years in dividend stocks; I'm still buying more today and will keep doing so until the price drops even further.
It's always inspiring to hear from a veteran investor who has weathered the storm and come out on top. When your portfolio turns from green to red, it might be unsettling, but if you have invested in great companies, you should just keep adding to them and stick with your plan.
I wholeheartedly concur, which is why I appreciate giving an investment coach the power of decision-making. Given their specialized expertise and education, as well as the fact that each and every one of their skills is centered on harnessing risk for its asymmetrical potential and controlling it as a buffer against certain unfavorable developments, it is practically impossible for them to underperform. I have made over 1.5 million dollars working with an investment coach for more than two years.
There are many financial coaches who excel in their profession, but for the time being, I employ "Jackson Sten Marsh," because I adore his methods. You can make research and find out more.
hehe
bruh
Internal Pointerrrr variable
สวัสดีค่ะขอบคุณค่ะ❤😂🎉😢😮😅😊
47:45
16:24