Menu

1 / 3

JavaScript Program to Find the Sum of the First and Last Digits of a Number

JavaScript in Plain English - Medium·Vikas·about 11 hours ago
#cXn47pD1
Reading 0:00
15s threshold

JavaScript Program to Find the Sum of the First and Last Digits of a Number

Vikas

2 min readOct 29, 2026

In JavaScript, we can find the sum of the first and last digits of a number using arithmetic operators, loops and string methods. This is a common programming problem for beginners who want to understand number manipulation in JavaScript.

For example, if the given number is 12345, the first digit is 1 and the last digit is 5. Their sum is 1 + 5 = 6.

In this article, we will learn different methods to find the sum of the first and last digits of a number in JavaScript with examples.

Problem Statement

Given a positive integer n, find the sum of its first and last digits.

Example 1:

Input:

n = 12345

Output:

6

Explanation: The first digit is 1 and the last digit is 5. Therefore, the sum is 1 + 5 = 6.

Example 2:

Input:

n = 9876

Output:

15

Explanation: The first digit is 9 and the last digit is 6.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.