They're both good aeroplanes and they can both get from A to B with a minimum of fuss and ease.
However, while they carry about the same amount of people, the A340 burns something like 8 tonnes per hour and the B777 more like 6 t/hr and it goes faster.
Why on earth would anyone buy an A340?