Palindrome number checking

Palindrome Number Checking Using TypeScript

I was facing problem to write basic programs like Palindrome number, Armstrong number, Prime number checking in JavaScript which I have already write many times in C language. I did little study and found that its easy to write using TypeScript which is the super set of JavaScript. I am assuming that you guys also already did palindrome number checking programming previously in other programming languages like C/C++, python, Java etc. In this article I will use TypeScript to do palindrome number checking using TypeScript. I guess you guys know the basics of Typescript. If no, that is also fine you can grab it easily. So, let’s start.

What is palindrome number?

If we reverse a number and the value of that number remains same then the number will be called Palindrome number.

Palindrome Number example: 12321, 121, 5463645, 111, 222, 32123 … etc

What is Typescript?

Basically, Typescript is a superset of JavaScript means Typescript content all properties of JavaScript. Typescript helps JavaScript developers to implement class, data types as we do in high level language. It makes easy to debug errors and simplify OOPs implementation in JavaScript.

It is very easy to learn if you know OOPs like class, interface etc. Its is lightweight and great for production. Now come to the article main point

To familiar more with typescript language can go and visit : Learn more

This program can be written on many ways. I have choose Typescript to implement the Palindrome number checking.

* Class based Palindrome number checking using TypeScript

class Palindrome{

// Declare number variables
x: number=0;    
y: number=0;    
temp: number=0; 

// Initialize variable using constructor
constructor(x: number=0){ 
 this.x = x;
 this.y = x;

// Palindrome number checking method
 this.temp = (this.x)%10 + (this.temp)*10;
 this.x = Math.floor(this.x/10);

    return "Number is Palindromic";
    return "Number is not Palindromic";

//Create objects
let obj  = new Palindrome(56365);
let obj1 = new Palindrome(1234);
let obj2 = new Palindrome(12321);

// Print in console 

Number is Palindromic Number is not Palindromic
Number is Palindromic

Conclusion: Palindrome number checking is a basic program to practicing any programming language. Which develops logical thinking of a programmer and as well as enhance the language fluency. So, keep learning and keep practicing.

Published by


I am a technology enthusiast, web developer and blogger by hobby. I like to meditate, run , eat fast foods and travel.

Leave a Reply

Your email address will not be published. Required fields are marked *