How does data conversion work between HTML and JavaScript?

18
May 18, 2019, at 5:40 PM
  • HTML5 documents are encoded in UTF-8, this means 1byte (8bits) per character

  • but JavaScript encodes strings in 2bytes (16bits) and numbers in 64bits

My question is

  • Does JavaScript convert every time it reads/writes HTML data? (I couldn't google any clear information about this mechanism)
Answer 1

JavaScript is not involved with this character conversion. It interfaces with the DOM interface. The DOM interface uses UTF-16. Its specification states:

A DOMString is a sequence of 16-bit units.

For Java and ECMAScript, DOMString is bound to the String type because both languages also use UTF-16 as their encoding.

The third player in the process is the browser engine (e.g. Gecko, WebKit,...), more broadly, the user agent. The browser engine takes care of character encoding conversions between the actual HTML file/page and the DOM API (and CSSOM API). See for instance what W3C has on HTML document representation:

Conforming user agents must correctly map to ISO 10646 all characters in any character encodings that they recognize (or they must behave as if they did).

JavaScript is not concerned with that.

READ ALSO
How to show all divs again when no filter-checkboxes are checked anymore?

How to show all divs again when no filter-checkboxes are checked anymore?

I've built a little filterDepending on the checkboxes you check, it will show boardgames for a certain amount of players and a certain amount of playing time

12
Text is not appearing after the second insert

Text is not appearing after the second insert

these code is working except that for the second or subsequent insert, the message 'Order added' is not appearingSecondly, after I removed everything using pop and click to view current order, the message 'No customer orders at the moment

21
Find min/max values from object array exlcuding infinity

Find min/max values from object array exlcuding infinity

I have an array of objects where I want to find the min/max value of a property in each objectI currently have a working method to find the min, however I am struggling with the max, if the value is Infinity I want to ignore it

43