In the US, this varies per state. In most states, though, it is illegal to "unnecessarily" honk your horn. But as the sibling commented about the UK, it's rarely enforced and is at the discretion of the officer.
I don't think most people know it is illegal.