 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
Advertisements
 