This line, when saved in a local html file, alerts 229:
<script>alert("基".charCodeAt(0))</script>
But when the alert is copied to JSFiddle, it provides 22522.
Why is there a difference?
This line, when saved in a local html file, alerts 229:
<script>alert("基".charCodeAt(0))</script>
But when the alert is copied to JSFiddle, it provides 22522.
Why is there a difference?
The reason is because JSFiddle charset is
utf-8
You will need to set the right charset inside your
meta
tag inside yourhead
tags.With the following meta tag it will show
22522
and without it will show229
:Please check the following Links:
ref_html_utf8
html_charset
Tested in local file with HTML looking like this: