In Javascript, you can nest a function within a function. The nested inner function is private to the…