# Should String.prototype.trim remove zero-width space? (\\u200b)

**URL:** <https://es.discourse.group/t/should-string-prototype-trim-remove-zero-width-space-u200b/1118>\
**Category:** I have questions\
**Created:** [December 10, 2021, 5:12am UTC](https://es.discourse.group/t/should-string-prototype-trim-remove-zero-width-space-u200b/1118 "2021-12-10T05:12:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aleen42](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aleen42/32/461_2.png) [@aleen42](https://es.discourse.group/u/aleen42)\
**Post date:** [December 10, 2021, 5:12am UTC](https://es.discourse.group/t/should-string-prototype-trim-remove-zero-width-space-u200b/1118/1 "2021-12-10T05:12:06Z")

</div>

REF: [Trim not removing zero-width spaces · Issue #182 · jprichardson/string.js · GitHub](https://github.com/jprichardson/string.js/issues/182)

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [December 10, 2021, 5:27am UTC](https://es.discourse.group/t/should-string-prototype-trim-remove-zero-width-space-u200b/1118/2 "2021-12-10T05:27:36Z")

</div>

The issue explains why a zero-width-space isn't included in the whitespace characters that `trim` removes.

---

<div class="post-metadata">

**Author:** ![aleen42](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aleen42/32/461_2.png) [@aleen42](https://es.discourse.group/u/aleen42)\
**Post date:** [December 10, 2021, 5:31am UTC](https://es.discourse.group/t/should-string-prototype-trim-remove-zero-width-space-u200b/1118/3 "2021-12-10T05:31:06Z")

</div>

So is there any discussion around the issue?

```javascript
/\s/.test('\u200b'); // => false
'\u200b'.trim().length; // => 1

```

As mentioned in [Whitespace character - Wikipedia](https://en.wikipedia.org/wiki/Whitespace_character), I have tested with the category of "`Related Unicode characters property White_Space=no`" with the following snippet:

```javascript
[
    '\u180e', '\u200b', '\u200c', '\u200d', '\u2060', '\ufeff'
].filter(ch => ch.trim().length);
// => ['\u180e', '\u200b', '\u200c', '\u200d', '\u2060]

```

I found that '\ufeff' is a special case.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [December 10, 2021, 6:22am UTC](https://es.discourse.group/t/should-string-prototype-trim-remove-zero-width-space-u200b/1118/4 "2021-12-10T06:22:53Z")

</div>

I'm not sure what discussion there would be? `trim` removes whitespace on the ends. `/\s/.test()` returns `true` for things that are considered whitespace.

You're welcome to try to convince Unicode to add the zero-width space to the whitespace category, but it wouldn't be appropriate for JS to violate this preexisting axiom.

---

<div class="post-metadata">

**Author:** ![aleen42](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aleen42/32/461_2.png) [@aleen42](https://es.discourse.group/u/aleen42)\
**Post date:** [December 10, 2021, 6:29am UTC](https://es.discourse.group/t/should-string-prototype-trim-remove-zero-width-space-u200b/1118/5 "2021-12-10T06:29:54Z")

</div>

So I want to know what the Unicode specification is according to in JavaScript? It seems the special case `\uFEFF` has been violated before according to [Unicode Utilities: UnicodeSet](https://util.unicode.org/UnicodeJsps/list-unicodeset.jsp?a=%5B:White_Space=Yes:%5D).

Oh, I see it. `\uFEFF` has been treated as Byte Order Mark (a.k.a BOM)
