I often want to write filenames for code.
Normally I write like this:
string = "This is example code"
Is this okay? Is there a standard Stack Overflow way of markdown for writing filename?
You can make a very nice-looking named code block using small headers and inline code, like so:
#### **`hello_world.js`** ``` js alert("Hello world!"); ```
I've accidentally found it in this post on Formatting Sandbox and just don't want this great trick to get lost there as I was unsuccessfully looking for this some time before.
Bolding is fine, though I think that the header markup you've used may be a little too forceful. Large text could help, though, if you had a lot of (hopefully small!) snippets in your post. I'm not sure we need a standard for this: use what makes your post most easily read and understood.
I will say, however, that code markup is definitely not the proper choice. The name of a file is not an element of a program; marking it as such is semantically incorrect.