It very much depends on the country. It's of course a huge advantage in countries where they don't speak English like Japan, and the Japanese generally like it when tourists at least try.
The French aren't huge fans of English, and I've met several people who would say stuff in French at me first despite me making it clear I didn't understand a word, then begrudgingly speak English.
Most Danes understand English and see no point in tourists leaning Danish. A simple "Tak" (thank you) is appreciated because it shows an interest, but Danes will generally get annoyed if you try something longer than that, start finishing your sentences and speak English to you. It can be super rude, but it's really just them telling you "It's okay, I understand English. Don't waste your time trying to learn Danish". So if you want to learn Danish it's best to practice with your friends rather than a random store clerk who'd much prefer you speak English.