Scope of a variable is the part of the program from where the variable may directly be accessible. In JavaScript, there are two types of scopes: Global Scope – Scope outside…