
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Squared concatenation of a Number in JavaScript
We are required to write a JavaScript function that takes in a number and returns a new number in which all the digits of the original number are squared and concatenated.
For example: If the number is −
99
Then the output should be −
8181
because 9^2 is 81 and 1^2 is 1.
Therefore, let’s write the code for this function −
Example
The code for this will be −
const num = 9119; const squared = num => { const numStr = String(num); let res = ''; for(let i = 0; i < numStr.length; i++){ const square = Math.pow(+numStr[i], 2); res += square; }; return res; }; console.log(squared(num));
Output
The output in the console will be −
811181
- Related Articles
- Smart concatenation of strings in JavaScript
- Checking for squared similarly of arrays in JavaScript
- Squared sum of n odd numbers - JavaScript
- Avoid Unexpected string concatenation in JavaScript?
- Next multiple of 5 and binary concatenation in JavaScript
- Integers have sum of squared divisors as perfect square in JavaScript
- Squared and square rooted sum of numbers of an array in JavaScript
- Are both addition and concatenation same in JavaScript?
- Concatenation of Strings in Java
- How to measure the mean squared error(squared L2 norm) in PyTorch?
- Check if a number is formed by Concatenation of 1, 14 or 144 only in C++
- String Concatenation by + (string concatenation) operator.
- Concatenation of strings in Lua programming
- Concatenation of tables in Lua programming
- Program to find minimum number of subsequence whose concatenation is same as target in python

Advertisements