There is a lot of confusion about that in the Web. Just do a web search and you will get a lot of different answers.
It seems like JS was originally designed in a way that it can't get your IP. People usually could do that using workarounds like requesting an external server to get your IP and then taking it back somehow. See Shog9's answer in Stack Overflow.
It changed recently with WebRTC. This standard empowers JS and makes it possible to get real IP using client-side code only. Fortunately TBB did not implement that standard.
You will find a lot of people saying that JS can give away your IP because someone could exploit some bug. While it's totally true, it's also true for every piece of software involved in Tor, so it's just no real answer.
document.write() and planting some plugin-related ip checkers, like flash pixel - or just simply make a XmlHttpRequest to the server-side script, returning an IP via JSON. There are alot of ways - and it's not TBB-specific, actually.