🚀 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
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
The
(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:
*
*
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.