In your first example, the benefits are negligible. The real benefit of anonymous functions is when you (as their name suggests), never give them a name, and pass them directly to another function.
The following is in pseudocode, since anonymous functions are a language agnostic concept. Say you have a function like:
function do-after-5-seconds(f) {
sleep(5000);
f();
}
You can then use it like:
do-after-5-seconds(function() {
print("Hello!");
});
There would be very little point in giving the "hello printing function" a name, since it will never be used anywhere else. It's thus given directly to do-after-5-seconds
.
This is a petty example, but often you'll have functions that you'll never use again, so there's no point in polluting the namespace by naming them.