Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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>

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

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 (:

over 4 years ago · Santiago Trujillo Denunciar

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.

over 4 years ago · Santiago Trujillo Denunciar

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.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda