How to hide or close the browser tab when this tab is inactive, or the user switch into another tab using pure JavaScript?

Example: When the tab is open the Google Map, and the user switch into another tab, the Google Map tab will be hide or close. Thank you

I'm new in javascript. Please help me