Skip to content

sumOfDigits ​

The sumOfDigits function returns the sum of the digits of a number.

Syntax ​

typescript
sumOfDigits(value)

Parameters ​

NameTypeDescription
valuenumberNumber to be analyzed.

Return Value ​

TypeDescription
numberThe sum of the digits of the given number.

Examples ​

typescript
sumOfDigits(123);   // 6
sumOfDigits(2023);  // 7

Notes ​

  • Throws a TypeError if the value is not a number.
  • Useful for mathematical algorithms, validation, and checksum.

References ​

Released under the MIT License.