Strings are one of the most frequently used data types in JavaScript, yet many developers rely heavily on built-in methods without truly understanding how they work under the hood. If you're preparing for interviews, this is a gap worth fixing.
JavaScript strings look simple, but behind methods like split(), trim(), includes(), and replace() is logic every developer should understand.
What string methods are
JavaScript provides built-in methods to manipulate strings:
toUpperCase()
Converts all characters in a string to uppercase.
let str = " hello world " ;
console . log ( str . toUpperCase ());
Enter fullscreen mode
Exit fullscreen mode
// "HELLO WORLD"
toLowerCase()
Converts all characters to lowercase.
let str = " HELLO " ;
console . log ( str . toLowerCase ()); // "hello"
Enter fullscreen mode
Exit fullscreen mode
trim()
Removes whitespace from both the beginning and end of a string.
let str = " hello " ;
console . log ( str .…