JavaScript Interview Prep: Functions, Closures, Currying

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

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

  • @mayursmahajan
    @mayursmahajan Год назад +21

    Bro literally saved my life today, I watched this video before the interview, It went excellent.

    • @Antonailzb
      @Antonailzb 10 месяцев назад +3

      did you get the job?

    • @mayursmahajan
      @mayursmahajan 10 месяцев назад +9

      @@Antonailzb Yes bro, I started 3 months ago here.

    • @Antonailzb
      @Antonailzb 10 месяцев назад +3

      @@mayursmahajan congrats bro! hope its been good to you

  • @pranavbhat29
    @pranavbhat29 Год назад +47

    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.

  • @abhishekmohanty232
    @abhishekmohanty232 Год назад +20

    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 😊

  • @WinchesterD
    @WinchesterD 8 месяцев назад +2

    Great course, from basic to advanced questions.

  • @Error_404_Dev
    @Error_404_Dev 2 месяца назад +2

    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.

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

    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.

  • @divinesovereign3103
    @divinesovereign3103 10 месяцев назад +1

    such an amazing content thank you so much! - a guy from the Philippines.

  • @yadiralugo2969
    @yadiralugo2969 3 месяца назад +1

    you explain so good! I am curious who is your employee. They are very lucky to have you.

  • @bobwear123
    @bobwear123 Месяц назад

    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";
    }
    };
    };
    }

  • @j2devstudio
    @j2devstudio 7 месяцев назад +4

    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

    • @waleedahmad3746
      @waleedahmad3746 3 месяца назад

      Give us the update bro, we gotta know how that interview went...

    • @RoadsideCoder
      @RoadsideCoder 2 месяца назад

      Thanks ❤

  • @lihonghan324
    @lihonghan324 Год назад +5

    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

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

      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.

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

    This is such a good prep, but also entertaining somehow, first time watching stuff like this.

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

    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
    }

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

    the manipulating DOM example does not seem to be of using currying, but more of using closure to store value of id.

  • @euroclydon7883
    @euroclydon7883 Год назад +6

    Roadside coder is here🔥🔥

  • @iuhere
    @iuhere Год назад +7

    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.

  • @shahmeerkhan1565
    @shahmeerkhan1565 3 месяца назад +1

    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...

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

    absolutely best timing, I have an interview tomorrow. thanks FCC !

  • @BlacksmokeBilly2
    @BlacksmokeBilly2 Месяц назад +2

    whole vid be like "go and watch THAT vid"

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

    Thank you so much for this video! Waiting for "this" video 😉

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

      Thanks, You can check that video here - ruclips.net/video/rv7Q11KWmKU/видео.html

    • @Mohammedrabeeh-fg1ww
      @Mohammedrabeeh-fg1ww Год назад

      @@RoadsideCoder 👍👍

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

    Excellent course, great video.

  • @דוידאללוףשרון
    @דוידאללוףשרון Год назад +4

    תודה!

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

    17:30 Its Rest *Parameter* and Spread *Operator*

  • @newaroundhere
    @newaroundhere 3 месяца назад

    Fantastic video

  • @mrdarkdayy9902
    @mrdarkdayy9902 Год назад +3

    You know the tutorial is going to be superior than others when the guy is Indian.

  • @songs123d
    @songs123d 9 месяцев назад +1

    Treasure content.

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

    Im already subscribed to his channel and love his content. ❤

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

    35:24 is so confusing because on hoisting 14:26 with var the behavior is not the same...

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

    Love the part on closures.

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

    Was I simply too afraid? Should I start applying? Are these really expected interview questions for entry level?

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

    i like the methods using shorthand syntax
    its like making your naming of functions more reusable

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

    Definitely needed this

  • @GAGANDEEPSINGH-fv2rt
    @GAGANDEEPSINGH-fv2rt Год назад

    This questions is very good for entry level js coding interview

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

    Do a java job prep

  • @tejasukalkar2199
    @tejasukalkar2199 Год назад +22

    I've interview tomorrow and this video came as blessing in disguise for me thank you @freecodecamp😊😊❤❤

    • @dhiyanabdurazack5257
      @dhiyanabdurazack5257 Год назад +13

      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.

    • @About-world1777
      @About-world1777 Год назад +1

      Did you pass your interview

    • @629_nishantghadigaonkar3
      @629_nishantghadigaonkar3 Год назад

      Can you tell me about your interview experience?

    • @abcproduction6819
      @abcproduction6819 Год назад +3

      He failed miserably … nobody learn coding by watch RUclips videos

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

      @@abcproduction6819 No I didn't

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

    thanks for this content will help me !

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

    57:57 i though using apply() on arrow functions doesnt affect it?

  • @Khadi-C
    @Khadi-C Год назад

    Thanks for this! I'm saving this for when I'm ready for interviews.

  • @elias-soykat
    @elias-soykat Год назад

    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");

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

    Can a value can be shared between sibling functions in a function in closures

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

    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?

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

      have the same question, no idea why the time is different

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

      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

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

      @@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.

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

      @@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

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

      @@kuubeu
      In the video
      unoptimized:
      find(a) // takes t1 milliseconds
      find(b) // takes t2 milliseconds
      // and t1

  • @ManishKumar-ud6kj
    @ManishKumar-ud6kj Год назад

    🎉 nice

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

    that's what i was waiting for 🏆 plss release more videos related to interview

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

    the infinite currying is like recursion

  • @yashvanthkumar2576
    @yashvanthkumar2576 11 месяцев назад

    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?

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

      - 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.

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

    Java interview prep next😊

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

    Awesome 👏

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

    สวัสดีค่ะขอบคุณค่ะ❤😂🎉😢😮😅😊

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

    Came in good time

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

    Great❤

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

    this closure thingy is huge stuff I just discovered today, thank you!

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

    Life saviour

  • @ayushraj-fq4gn
    @ayushraj-fq4gn Год назад +17

    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

  • @uhicamfro
    @uhicamfro 2 месяца назад

    shuru woh angrez kaun tha??

  • @NoHorizon-
    @NoHorizon- Год назад

    How did he move square() to console log? I mean what is she shortcut?

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

      That's called a cut in the video, my guy

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

      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.

  • @argylleagen
    @argylleagen 7 месяцев назад

    20:00 🔖

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

    Thanks!

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

    awesome!1

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

    I understood nothing

  • @SphereofTime
    @SphereofTime 4 месяца назад

    1:23:00

  • @nick-pu4zae
    @nick-pu4zae Год назад

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

    CURRYing

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

    We need dart language

  • @rushikeshmanwatkar617
    @rushikeshmanwatkar617 14 дней назад

    This video has lot of incorrect information, please correct the concept of closures if you could.

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

    Can someone explain 9:10?

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

      To understand that better, you need to understand scope of var, let and const. Just watch my var,let,const video!

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

    Referenceerror: function not working

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

    Could I cooperate with you on promotional video about software? Thanks

  • @公主_maya
    @公主_maya Год назад +2

    There's a joke somewhere to be made here about currying lol

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

    Pdf de do

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

    25:19

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

    too much ads, every 3 minutes he advertised his product.

  • @blogactivities5462
    @blogactivities5462 7 месяцев назад +1

    this video leads new programmers to terrible mistakes / I do not recommend

    • @argylleagen
      @argylleagen 7 месяцев назад

      Could you elaborate on that?

  • @aammssaamm
    @aammssaamm Год назад +3

    Why do you need to yell? Do you think we are deaf?

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

      hahahahahahahahaahahahahahahahaahahahahahahahahaahahahah

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

    Dond dell me whad uoo duooo please 😅

  • @josephlee4001
    @josephlee4001 Год назад +5

    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.

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

      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.

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

      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.

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

      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.

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

    hehe

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

    bruh

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

    Internal Pointerrrr variable

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

    สวัสดีค่ะขอบคุณค่ะ❤😂🎉😢😮😅😊

  • @JOJO_THE_PROGRAMMER
    @JOJO_THE_PROGRAMMER 7 месяцев назад

    47:45

  • @SphereofTime
    @SphereofTime 4 месяца назад

    16:24