TGViewer
Web Development - HTML, CSS & JavaScript Web Development - HTML, CSS & JavaScript @javascript_courses · 55.7K subscribers
Post #3715 1.66K
🔹 Escape Characters

2️⃣5️⃣ New Line

You can use \n and \t:

const message1 = "Hello\nWorld";
console.log(message1);
// Hello
// World

const message2 = "Name:\tRahul";
console.log(message2); // Name: Rahul (with tab)


🔹 Comparing Strings

2️⃣6️⃣ String Comparison

Strings can be compared:

console.log("apple" === "apple"); // true
console.log("Apple" === "apple"); // false - case-sensitive

const input = "ADMIN";
if (input.toLowerCase() === "admin") {
console.log("Access granted");
}


⭐ Practical String Processing

Imagine a user enters an email:

const input = " USER@GMAIL.COM ";
const email = input.trim().toLowerCase();
console.log(email); // user@gmail.com

if (email.includes("@")) {
console.log("Email looks valid");
}


This combines:

• trim() ↓ toLowerCase() ↓ includes()

🧠 Real-World Example

Suppose you receive this data:

const data = "Amit, Priya, Rahul, Neha";
const names = data.split(",");
const cleanedNames = names.map(name => name.trim());

console.log(cleanedNames); // ["Amit", "Priya", "Rahul", "Neha"]

const filteredNames = cleanedNames.filter(
name => name.startsWith("R")
);

console.log(filteredNames); // ["Rahul"]


⚠️ Common Beginner Mistakes

• Mistake 1: Forgetting that strings are zero-indexed

const word = "Hello";
console.log(word[0]); // H not e


• Mistake 2: Expecting string methods to modify the original string

const name = "rahul";
name.toUpperCase();
console.log(name); // still "rahul"

const upperName = name.toUpperCase(); // correct


•

Mistake 3: Forgetting trim()

• User input often has accidental spaces: " Rahul "

•

Mistake 4: Confusing split() and join()

• split() → string → array

• join() → array → string

💻 Practice

•

1️⃣ Reverse a String: Given const word = "JavaScript"; Try to produce tpircSavaJ. Hint: split() + reverse() + join()

•

2️⃣ Count Characters: Count characters in "JavaScript"

•

3️⃣ Convert to Uppercase: Convert "javascript is powerful" to uppercase.

•

4️⃣ Extract Text: From "JavaScript" extract Script

•

5️⃣ Replace Text: Convert "I love Python" into "I love JavaScript"

•

6️⃣ Clean User Input: Given const input = " HELLO JAVASCRIPT "; Produce hello javascript

•

7️⃣ Challenge: Given const email = " USER@EXAMPLE.COM ";

Create a cleaned version that:

- Removes extra spaces

- Converts everything to lowercase

- Checks whether it contains @

- Prints "Valid email format" if it does.

🧠 Double Tap ❤️ For More
  • ❤ 7
More from @javascript_courses
  1. Oct 4, 2026DSA Handwritten Notes
  2. Sep 28, 2026To learn web design and development from basic to advanced levels, you can follow these st…
  3. Sep 27, 202610 Websites Every Developer & AI Enthusiast Should Bookmark ✅ roadmap.sh – Step-by-step le…
  4. Sep 26, 2026const fileName = "report.pdf"; console.log(fileName.endsWith(".pdf")); // true 🔹 Finding…
  5. Sep 26, 2026💻 JavaScript Roadmap 2026 — Part 8 🟢 Strings & String Methods Strings are used to repres…
  6. Sep 23, 2026The best doesn't come from working more. It comes from working smarter. The most common mi…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →