codebypc
2.09K subscribers
210 photos
59 videos
160 files
250 links
Html, css3, javascript, reactjs, express, Fullstack, backend, Bootstrap, mongodb
Download Telegram
🚀 New journey alert!


I’ve started a new page @englishbypc 🗣 to help with daily English & interview conversations.

Just posted my first reel (HR–Candidate phone call 📞).
Would love your support ❤️ Go check it out & follow!

👉 @englishbypc
1
☝️☝️Follow this page to improve your spoken English every day.
The trim() method in JavaScript is used to remove whitespace from both the beginning and the end of a string.
(It does not change the original string; instead, it returns a new string.)

Syntax:


string.trim()


Example:


let str = " Hello World! ";
console.log(str.trim()); // "Hello World!"


Key Points:

Removes spaces, tabs, and line breaks only from start and end, not in between.
Does not modify the original string.
Returns a new string.

Example with spaces inside:


let name = " PC Prajapat ";
console.log(name.trim()); // "PC Prajapat" (inner spaces stay)


👉 Related methods:

* trimStart() → removes whitespace only from the start.
* trimEnd() → removes whitespace only from the end.