You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Notice that the first listed character in the string literal (`"\u{5e9}"`) is actually the right-most character when the string is rendered?
279
+
280
+
Even though Hebrew is an RTL language, you don't actually type the characters in the string literal in reversed (RTL) order the way they should be rendered. You enter the characters in logical order, where position `0` is the first character, position `1` is the second character, etc. The rendering layer is where RTL characters are reversed to be shown in their correct order.
281
+
282
+
That also means that if you access `hebrewHello[0]` (or `hebrewHello.charAt(0)`) -- to get the character as position `0` -- you get `"ש"` because that's logically the first character of the string, not `"ם"` (logically the last character of the string). Index-positional access follows the logical position, not the rendered position.
283
+
284
+
Here's the same example in another RTL language, Arabic:
285
+
278
286
```js
279
287
arabicHello ="\u{631}\u{62d}\u{628}\u{627}";
280
288
281
289
console.log(arabicHello); // رحبا
282
-
```
283
290
284
-
If you access `hebrewHello[0]` -- to get the character as position `0` -- you might expect the letter `"ם"`, but instead you get `"ש"` because Hebrew is RTL. So in other words, JS applies index positioning based on the LTR/RTL of the locale (including as embedded in the string contents themselves).
291
+
console.log(arabicHello[0]); // ر
292
+
```
285
293
286
-
JS programs can force the in-effect language/locale, using various `Intl` APIs such as `Intl.Collator`: [^INTLCollator]
294
+
JS programs can force a specific language/locale, using various `Intl` APIs such as `Intl.Collator`: [^INTLCollator]
0 commit comments