Reversing Strings and Numbers in JavaScript with Functions

🚀 Day 2 of My Coding Journey Today I practiced an important concept: Reversing a String and a Number using Functions in JavaScript 🔹 What I learned: How to reverse a string using a loop How to reverse a number using mathematical logic Also explored shortcut methods using built-in functions 💻 Example: Reversing a String function reverseString(str) { let reversed = ""; for (let i = str.length - 1; i >= 0; i--) { reversed += str[i]; } return reversed; } Reversing a Number function reverseNumber(num) { let reversed = 0; while (num > 0) { let digit = num % 10; reversed = reversed * 10 + digit; num = Math.floor(num / 10); } return reversed; } 📌 Key Takeaway: Understanding logic is more important than just using built-in methods. I’m improving step by step every day 💪 #Day2 #JavaScript #CodingJourney #WebDevelopment #90DaysOfCode #Learning #FrontendDeveloper

To view or add a comment, sign in

Explore content categories