filmov
tv
Frontend Interview Question | What are Pure Functions? | SideEffects | Javascript Interview
Показать описание
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
Check video on Recursion
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:
For more such interesting videos, please subscribe to my channel and stay connected.
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
Check video on Recursion
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:
For more such interesting videos, please subscribe to my channel and stay connected.
Комментарии