Member-only story

10 JavaScript String Tricks Every Developer Should Know

habtesoft
2 min readDec 1, 2024

JavaScript strings are more than just a way to handle text — they’re a powerful tool with plenty of built-in methods to simplify your coding tasks. Here are 10 must-know tricks to help you harness the full potential of JavaScript strings.

Not a Medium member? Read this article here

1. Reverse a String in One Line

Reversing a string can be done with a simple combination of methods:

const reverseString = str => str.split('').reverse().join('');
console.log(reverseString("hello")); // Output: "olleh"

2. Check if a String Contains Another String

Using includes, you can quickly check for substrings:

const contains = str => str.includes("world");
console.log(contains("hello world")); // Output: true

3. Convert a String to Title Case

Capitalize the first letter of each word:

const toTitleCase = str => str.split(' ')
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
.join(' ');
console.log(toTitleCase("javascript string tricks")); // Output: "Javascript String Tricks"

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

habtesoft
habtesoft

Written by habtesoft

Passionate JavaScript developer with a focus on backend technologies. Always eager to connect and learn. Let’s talk, https://buymeacoffee.com/habtesoftat

Responses (8)

What are your thoughts?

Can you plz make it public I am not able to read

19

Reversing a string can be done with a simple combination of methods:

This is not a good way of doing it, as it will break if you try to reverse a string using emojis. Much better, although still not perfect, to use:
const reverseString = str => [...str].reverse().join``

11

Very useful, thanks alot

2