Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript

What is the trim() method in JavaScript?

Umme Ammara

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code

The trim() method in JavaScript removes the whitespace from both ends of a string without changing the original string. The functionality of trim method is shown in the illustration given below:

Syntax

The trim() method is declared as follows:

Parameters

The trim method does not take any parameters.

Return value

The trim method returns a string with whitespace removed from both ends of the string.

Example

The example below shows the use of trim method in JavaScript:

var str = " Hello! ";
//Call trim() method
console.log(str.trim());
var str2 = "How are you ? ";
//Call trim() method
console.log(str2.trim());

RELATED TAGS

javascript

CONTRIBUTOR

Umme Ammara
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Answers Code
Keep Exploring