Reverse a Number in JavaScript using while Loop | Step-by-Step Dry Run (2026)

Опубликовано: 16 Июль 2026
на канале: AshishCoding
64
4

In this video, you will learn how to Reverse a Number in JavaScript using a while loop and the modulus operator % We extract each digit using n % 10, build the reversed number using rev = rev * 10 + digit, and then remove the last digit using Math.floor(n / 10) — all traced step by step in a complete dry run.

By the end of this video, you will clearly understand how the while loop condition n greater than 0 works, how each digit is extracted and placed, and how the final reversed number is printed using console.log.

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━⏱️ TIMESTAMPS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
0:00 Introduction
0:45 What is sum of array elements?
2:00 Array declaration and index explained
3:30 for Loop with arr.length explained
5:30 How sum += arr[i] works
7:30 Step-by-Step Dry Run (i=0 to i=3)
11:00 Final Output using console.log
12:30 Outro

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
📌 WHAT YOU WILL LEARN
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔢 What is reversing a number in JavaScript
🔄 How while loop runs with condition n greater than 0
➗ How n % 10 extracts the last digit each time
📋 How rev = rev * 10 + digit builds the reverse
🧪 Complete dry run — trace 1234 → 4321 step by step
🖥️ How to print the reversed number using console.log


━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🔗 RELATED VIDEOS
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
▶ Fibonacci Series in JavaScript –    • Fibonacci Series in JavaScript using for L...  
▶ Factorial Program in JavaScript –    • Factorial Of Number in JavaScript using fo...  
▶ Swap Two Numbers in JavaScript –    • Swap Two Numbers in JavaScript using Third...  
▶ Remove Duplicates from Array in JavaScript –    • Remove Duplicates from Array in JavaScript...  

If this video helped you, please give it a LIKE and SUBSCRIBE to AshCodesX for more JavaScript tutorials every week. Drop your questions in the comments — I read every one!

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

🔑 KEYWORDS:
sum of array elements in javascript, javascript array sum using for loop, sum of array javascript, javascript sum += arr[i], array loop javascript beginner, javascript arr.length tutorial, find sum of array javascript, javascript for loop array program, javascript dry run, learn javascript 2026

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

#JavaScript #ArraySum #JavaScriptArray #SumOfArray #JavaScriptForLoop #JSforBeginners #LearnJavaScript #DryRun #JavaScriptTutorial #CodingForBeginners #WebDevelopment #AshCodesX