user6084875
user6084875

Reputation:

Is this pure functional? using a value in the nested (Closure like) function

Using a value in the nested (Closure like) function such as:

const f1= () => {
    const a = 1;
    const f2 = () => a;
    return f2;
    };

f2 does not have arg of a, but returns a of the upper-scope of f1.

Upvotes: 0

Views: 110

Answers (1)

Bergi
Bergi

Reputation: 664548

Yes.

a is a constant and referentially transparent. It doesn't matter that f2 is a closure as long as it does not close over mutable state.

Upvotes: 2

Related Questions