Javascript examples for Data Type:Number
Add digit from a number
<html> <head> <meta name="viewport" content="width=device-width"> </head> <body> <script> var addDigits = function a(num) { var length=num.toString().length; var value=num.toString();/*w ww . j ava2 s. co m*/ var sum=0; for(var i=0;i<value.length;i++) { sum+=Number(value[i]); } return sum; }; console.log(addDigits(123456789)); </script> </body> </html>