There is no worse developer experience than bad example code in the documentation.
It is easy to make mistakes in code slightly more complicated than a Hello World program. In fact, in Hello World as well.
It is advisable to test the example codes in the documentation, like all code. Since the example codes also change over time, this testing should be done automatically, built into the documentation release process.