You kind of need both to some degree, if you’re going to test in the editor, Application.Quit() isn’t going to give you results, but stopping the playing will function in the editor. Otherwise you will need to build it out each time so it’s not hosted in the Unity Editor and can respond to Application.Quit method.
This way when a user of the application(or developer) presses escape in a frame and is in the editor, the editor stops playing the current scene. If it’s not in the editor it invokes Application.Quit()