Note: A current window/tab will only get closed if and only if it was created & opened by that script.Means the window.close syntax is only allowed for the window/tab that is created & opened using window.open method.
Example: This example shows how to open GeekForGeeks window and then close it.
When we load the code:
New Window/Tab gets opened up:
The Window/Tab gets closed:
The entire process: