You can create an IIFE around it:
(function(){
var count = 0;
$('body').on('click', '.a', function() {
count++;
console.log(count)
});
})();
Javascript has function scoping, so count
will be local to that outer anonymous function.