I think what you are looking for is.
var userName = $.getenv($.os == "M" ? "USER" : "username"); alert(userName);
I updated the quotes in the snippets because they got messed up.
I noticed the quote issue and got it working before you updated it.
How do you learn this stuff?
One good source is this forum. There's also stack exchange and most importantly Google.
I have some good ebooks and a few years / decades of experience can come in useful too.
Regarding Indesign scripting there's quite a bunch of them with some very good content to them. I hope to be adding my own contribution soon http://creative-scripts.com at the moment it doesn't have any content but it's starting to get a shape.
The answer I gave I copied from a comment I posted on Loic's site
That's were the quotes got messed up. I see on my site it does the same so I shall do a quick google on how to fix that