Skip to content

Commit be5baf9

Browse files
Drop bad example of String.p.trim() (mdn#3962)
* Fix flaws * Drop bad example of String.p.trim() Also, in the Description section add some prose: > To return a new string with whitespace trimmed from just one end, use > trimStart() or trimEnd(). Fixes mdn#3961
1 parent cb7802d commit be5baf9

File tree

1 file changed

+9
-12
lines changed
  • files/en-us/web/javascript/reference/global_objects/string/trim

1 file changed

+9
-12
lines changed

files/en-us/web/javascript/reference/global_objects/string/trim/index.html

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
title: String.prototype.trim()
33
slug: Web/JavaScript/Reference/Global_Objects/String/Trim
44
tags:
5-
- ECMAScript 5
6-
- JavaScript
7-
- Method
8-
- Prototype
9-
- Reference
10-
- String
5+
- ECMAScript 5
6+
- JavaScript
7+
- Method
8+
- Prototype
9+
- Reference
10+
- String
1111
---
1212
<div>{{JSRef}}</div>
1313

@@ -19,7 +19,7 @@
1919

2020
<h2 id="Syntax">Syntax</h2>
2121

22-
<pre class="brush: js"><code><var>str</var>.trim()</code></pre>
22+
<pre class="brush: js">str.trim()</pre>
2323

2424
<h3 id="Return_value">Return value</h3>
2525

@@ -32,6 +32,8 @@ <h2 id="Description">Description</h2>
3232
ends. <code>trim()</code> does not affect the value of the <code><var>str</var></code>
3333
itself.</p>
3434

35+
<p>To return a new string with whitespace trimmed from just one end, use {{jsxref("String.prototype.trimStart()", "trimStart()")}} or {{jsxref("String.prototype.trimEnd()", "trimEnd()")}}.</p>
36+
3537
<h2 id="Polyfill">Polyfill</h2>
3638

3739
<p>Running the following code before any other code will create <code>trim()</code> if
@@ -52,11 +54,6 @@ <h3 id="Using_trim">Using <code>trim()</code></h3>
5254

5355
<pre class="brush: js">var orig = ' foo ';
5456
console.log(orig.trim()); // 'foo'
55-
56-
// Another example of .trim() removing whitespace from just one side.
57-
58-
var orig = 'foo ';
59-
console.log(orig.trim()); // 'foo'
6057
</pre>
6158

6259
<h2 id="Specifications">Specifications</h2>

0 commit comments

Comments
 (0)