It would be highly overcomplicated, but theoretically you could make sure that all the code execution happens in a scope you define via an anonymous function.
This way everything executed via the console would be in a different scope (which is the default one) and you could potentially add code to every public function you have where you check from where that code is being executed.
But again, the user has complete control over the browser.
I read that you noticed this when playing a game. http://agar.io for instance uses this isolated scope technique to avoid a user to tamper with game values. This is not foolproof as a savvy user could still attempt to code inject your code to add handles to expose internal pieces of your code.
You can although implement some tricks to make it more difficult to the user (see https://x-c3ll.github.io/posts/javascript-antidebugging/)