What is the logic behind the output of the following examples:
console.log('\272') // -> º
console.log('\364') // -> ô
As far as I know, \
is an escape character in javascript which means it tries to escape the following character but in the first example it is not equal to ASCII code of 72 which is character H
.
That's because of the octal encoding.
Any character with a character code lower than 256 (i.e. any character in the extended ASCII range) can be escaped using its octal-encoded character code, prefixed with . (Note that this is the same range of characters that can be escaped through hexadecimal escapes.)
To use the same example, the copyright symbol ('©') has character code 169, which gives 251 in octal notation, so you could write it as '\251'.
You can take a look to this explanation, quite illustrative: https://mathiasbynens.be/notes/javascript-escapes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With