Become a member
to unlock all features

    Identify Side Effects by Comparing Pure and Impure JavaScript Functions


    This lesson teaches you the difference between pure and impure functions through examples of both. Pure functions are any functions whose output is solely derived from its inputs and causes no side effects in the application or outside world. Mathematical functions are examples of pure functions.

    Impure functions come in a variety of shapes and sizes. Some typical examples would be:

    • Functions whose output depends on outside/global state
    • Functions that return different outputs for the same inputs
    • Functions that modify application state
    • Functions that modify the "outside world"

    Functional programming is built upon the use of pure functions and the strict control of side effects. Being able to recognize either type of function is a key fundamental for functional programming.