Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Check for perfect square in JavaScript
We are required to write a JavaScript function that takes in a number and returns a boolean based on the fact whether or not the number is a perfect square.
Examples of perfect square numbers −
Some perfect square numbers are −
144, 196, 121, 81, 484
Example
The code for this will be −
const num = 484;
const isPerfectSquare = num => {
let ind = 1;
while(ind * ind <= num){
if(ind * ind !== num){
ind++;
continue;
};
return true;
};
return false;
};
console.log(isPerfectSquare(num));
Output
The output in the console −
true
Advertisements