Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

180
Views
Is there any difference between $.trim and trim?

I have this simple example below which uses trim. As per the title of the question, is there any difference between them?. As you can see below they have the same output. If the answer is "No", which one is much better to use?

Currently I use .trim() because it's my first time seeing $.trim().

var SampleTrim = '     TRIM         ';

console.log(SampleTrim.trim());
console.log($.trim(SampleTrim));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

String.prototype.trim is not available below IE9, otherwise they are the same.

The recommended String.prototype.trim polyfill on MDN is exactly the same as that used in jQuery source.

In most cases, the native implementation would be faster to use. This JSPerf by Sumit Gulati suggests that too.

Realistically, the difference in performance would be quite negligible and I wouldn't base my decision on performance. However, it would be better to use the native implementation so that there's no dependency on jQuery. The large websites have dropped support for IE8 and I think it's safe to follow suit (:

about 4 years ago · Santiago Trujillo Report

0

jQuery's trim() function was available long before JavaScript's native trim() function was added, which is available in browsers above IE9 and the like.

Use the native trim function for future projects.

about 4 years ago · Santiago Trujillo Report

0

As I know, SimpleTrim.trim() is a native way to trim a string that modern brower support.

And $.trim(SimpleTrim) is another way that jQuery help user in the past to trim string, when browser does not support native trim.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!