JavaScript: Entity in document.title

How can I add a dash to my document.title using JavaScript?
<script type="text/javascript">
 document.title='Hello &#8212; World';

Open in new window

LVL 16
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

David S.Connect With a Mentor Commented:
Special characters are written differently in JavaScript than they are in HTML. More info:,_Variables,_and_Literals#Unicode_Escape_Sequences

You convert the number to hexadecimal (assuming you're using a decimal character entity) and prefix it with "\u", like this:
document.title='Hello \u2014 World';

Open in new window

Which browser version?
Work for me :
document.title = "Hello - World"

Open in new window

hankknightAuthor Commented:
Thanks, but my question is about how to get a numbered entity into the title.

"—" is NOT the same a "-", it is much wider.  I want to define it with the entity number, &#8212;
leakim971Connect With a Mentor PluritechnicianCommented:
Ok, new one :

document.head.getElementsByTagName("title")[0].innerHTML = "Hello &#8212; World";

Open in new window

All Courses

From novice to tech pro — start learning today.