Short answer: clear all; deletes a.
Your immediate problem should be solved just by omitting the 'clear all'. Unless you want to specifically clear 'a' for some reason there is no point of the clear command in your function anyways. Functions have their own workspace, I cannot think of a good reason to put a 'clear all' in any function.
I'd also like to advice to not use global variables. There is usually a cleaner way; for example you could create a property a in your app and then use app.a instead of your global variable or use a toggle button and check the state of the button.