Palindrome Java vs JavaScript

Why does Java work while JavaScript does not? I tried using this in Java, and it worked just fine, but in JavaScript, it only prints “Not a palindrome.” How come? Many thanks.

var n = 121;
 var sum = 0, r;
 var temp = n;    
 while(n>0)
   {    
    r = n % 10;   
    sum = (sum*10)+r;    
    n = n/10;    
   }    
  if(temp==sum)    
    console.log("It is a Palindrome number.");
  else  
    console.log("Not a palindrome");