Check out example codes for "unity how to end a game with esc". It will help you in understanding the concepts better.

Code Example 1

void Update()
{
    if (Input.GetKey(KeyCode.Escape))
    {
        Application.Quit();
    }
}

Learn ReactJs, React Native from akashmittal.com