Where "Foo" and "Bar" Came From
The two most-repeated origin stories — a WWII acronym, and a 1930s comic strip — both check out, and the more surprising finding (documented in an actual IETF standards document written specifically to settle this, RFC 3092) is that the comic strip almost certainly came first.[1]
The comic strip nobody expects
"Foo" shows up in print well before any wartime acronym: in Smokey Stover, a wildly popular American newspaper comic strip that ran from roughly 1930 to 1952, where the title character (a firefighter) used "foo" as a nonsense catchphrase constantly.[2] The strip was popular enough to spin off over 500 unofficial "Foo Clubs" and work its way into contemporary songs — it was, briefly, just a piece of mainstream American pop culture, the way a meme phrase spreads today.
Where FUBAR actually fits
FUBAR ("[messed] up beyond all recognition/repair") is real WWII-era US Army slang, and "foo fighter" was genuinely used by WWII radar operators for unexplained blips — the same term that later got attached to UFO sightings, and, much later, to the rock band.[3] For years the assumed story was that "foo" in computing came from an informal shortening of FUBAR. RFC 3092's actual research points the other way: contemporary accounts tie WWII "foo fighter" directly back to the already-famous comic strip, not the other way around, and there's a real possibility FUBAR itself picked up its spelling under the influence of "foo" (with a nod to the similar-sounding German word furchtbar, "terrible") rather than "foobar" being a sanitized version of FUBAR. In short: the acronym almost certainly didn't invent the word, it more likely borrowed it.
How it got into code
The jump from slang to programming is credited to MIT's Tech Model Railroad Club, around 1960 — the same group whose model-railroad-control jargon fed heavily into what became early hacker culture and, eventually, the Jargon File itself.[4] "Foo" needed a placeholder pair once code examples needed a second arbitrary thing, and "bar" — already sitting right next to it via FUBAR — was the obvious choice. From there the family just grew: baz, qux, quux, and others exist purely because someone needed a third, fourth, or fifth interchangeable nothing-word and reached for whatever sounded like it belonged in the same set. None of them mean anything. That's the entire point of a metasyntactic variable — a name that signals "this could be replaced with literally anything" precisely by not meaning anything itself.
Foo, bar, and dord all end up in the same place, incidentally: a word that only exists because of how it was used, not because anyone set out to define it. See Dord: The Word the Dictionary Invented by Accident for the version where that happened entirely by accident, inside a real published dictionary.