Free Variable: Free variables are simply the variables that are neither locally declared nor passed as parameter. We know about scope in JavaScript, We create private variables to enable encapsulation. To write Function or variables created in a function has local scope and not accessible out from that function blocks.…