The #if UNITY_EDITOR is an kind of Platform Dependent Compilation, this prevents anything that isn’t the UnityEditor to run the code. You could do the same with Android for example, to make something run only if it is executed within an Android device.
The UnityEditor.EditorApplication.isPlaying is the bool responsible for saying if the application is actually running or not, it only works when you are executing within the unity editor, if you change it to false it will stop the application as observed. And the Application.Quit() only works for actually builds, and don’t work within the editor alone.
These special if/else statements are there only to make sure that the right method will be used to stop the application regardless if you are within the Editor or in the actual build. You could for example add one more if to handle the case when the player clicks on the quit button within an webgl build, and you can try a different approach to those two methods since probably neither would work for Webgl