Hoisting in JavaScript is a unique mechanism that moves declarations to the top of the current scope (either function or…