Hoisting is a behaviour in JavaScript where variable and function declarations are moved to the top of…