Frontend Interview Question | What are Pure Functions? | SideEffects | Javascript Interview

Sdílet
Vložit
  • čas přidán 30. 06. 2024
  • Hello Everyone
    In this session, we will learn about Pure Functions in Javascript and this is one of the asked question in Interview .
    What are Pure Functions?
    Function that produces the same output for the same input. It means it returns the same result when you pass the same arguments. A pure function shouldn't have any side effects to change the expected output
    We need to make sure functions are,
    Predictable: It produces a predictable output for the same inputs.
    Readable: Anyone reading the function as a standalone unit can understand its purpose completely.
    Reusable: Can reuse the function at multiple places of the source code without altering its and the caller's behavior.
    Testable: We can test it as an independent unit.
    What is SideEffect ?
    Any operation that is not directly related to the final output of the function is called a Side Effect
    A few more classic cases of the side effects are,
    1)Mutating(changing) the input itself.
    2) Querying/Updating DOM
    3 )Logging(even in the console)
    4) Making an XHR/fetch call.
    Check another important interview Question
    • Frontend Interview Que...
    Check video on Recursion
    • What is Recursion | Ja...
    Support my channel by liking and sharing my videos so that I can reach to wider audience. Please share it in your network 🙏
    Connect with me on social platform:
    Facebook: / angularjs4beginners
    LinkedIn: / nisha-singla-82407aa0
    Instagram : / nishasingla05
    Twitter: / nishasingla05
    For more such interesting videos, please subscribe to my channel and stay connected.

Komentáře • 10

  • @buntykhipal5103
    @buntykhipal5103 Před 6 měsíci

    this video helped me a lot to learn difference between pure and impure function
    thank for making video

  • @gyanendra_chaubey
    @gyanendra_chaubey Před rokem +1

    Your questions are awesome and you are doing great job. Is it possible for you to add more FE questions especially tricky ones like the one (async + settimeout + promises one). Anyways thank's for what ever you have posted till date.

  • @RahulKumar-ew1qw
    @RahulKumar-ew1qw Před 2 lety

    Great explanation. Ms

  • @krishtechhq
    @krishtechhq Před 2 lety +1

    Nice !

  • @miw879
    @miw879 Před 2 lety +2

    very nicely explained :)

  • @rajesh.geesala7565
    @rajesh.geesala7565 Před 7 měsíci

    Thanks

  • @BrijeshSingh-dp1ku
    @BrijeshSingh-dp1ku Před 2 lety +1

    Hi Nisha, thanks for sharing.. where you work?