While working on Qvault’sGo Playground, I came across a very strange error. For those of you who are familiar with the function, when compiled to a “normal” executable fmt.Printf prints a formatted string to standard output.

However, if you change the program slightly: Then it may print the expected: thought if you run the two programs back to back, you may actually find that this is printed instead: As far as I’ve been able to gather, when compiled to Web Assembly, the fmt.Printf function is writing to a buffer, and that buffer is not cleared until a newline character is printed to standard out. In other words, you can call fmt.Printf as many times as you want, but nothing is printed until a \n character comes through standard output. My current working theory is that it works this way because there is no way to print to the console in a browser without appending a newline.

Related Articles