A cube number (perfect cube) is an integer n that equals k3 for some integer k. Both 0 and negative cubes count.
Remember
n is a cube number ⇔ n = k × k × k for some integer k
Examples:
0 = 0³
1 = 1³
8 = 2³
27 = 3³
−8 = (−2)³
10 → not a cube
k
k³
Cube?
0
0
Yes
2
8
Yes
3
27
Yes
—
10
No
First non-negative cubes
List
0, 1, 8, 27, 64, 125, 216, 343, 512, 729, 1000
Approach
How to Check a Cube Number in JavaScript
Four clear steps — then pick an integer scan or a cube-root check.
Work with |n| if you want a nonnegative search (re-apply the sign for negatives).
Find an integer k whose cube might equal the value.
Verify with exact integer multiplication: k * k * k === n (on the absolute value).
Never trust a floating-point cube root alone — always verify.
Method
Idea
Time
Best for
Integer scan
Increase k while k³ < |n|
O(∛|n|)
Interviews, no floating point
cbrt + verify
Round Math.cbrt, then check k³ === |n|
O(1)
Quick answers, typical safe integers
Pseudocode
Pseudocode
function IsCube(n):
target = abs(n)
k = 0
while k * k * k < target:
k = k + 1
if k * k * k != target:
return false
return true
Reference
Cheat Sheet
Keep these facts handy while writing the program.
Topic
Detail
Definition
n = k³ for some integer k
Always cubes
0, 1, −1
Verify
Use integer k * k * k === target
Avoid
Trusting Math.cbrt without a re-check
Large values
Stay within safe integers, or use BigInt
Classic check
27 → yes (3³); 10 → no
Try it
Live Preview
Enter any integer to see whether it is a perfect cube and which k produces it.
Whole numbers (capped at ±999999999). Tap a chip or type a value.
Result
n = 27
k = 3
Check: 3 × 3 × 3 = 27
Verdict: CUBE NUMBER
Code
JavaScript Programs
Start with a pure integer scan. Then use Math.cbrt with an integer verification for a short production-style check.
Example 1 — Integer Scan
Walk k upward until k³ meets or passes |n|, then compare.
JavaScript
function isCube(n) {
const target = Math.abs(n);
let k = 0;
while (k * k * k < target) {
k++;
}
return k * k * k === target;
}
const number = 27;
if (isCube(number)) {
console.log(number + " is a cube number.");
} else {
console.log(number + " is not a cube number.");
}