Get current domain name in javascript

In javascript the window.location object can be used to get the current domain name.

<script>
alert("current domain is " + window.location.hostname)
</script>