whatstheoutput_

#29: 2 ** 3 ** 2

Topic: numbers · Difficulty: ★

console.log(2 ** 3 ** 2);

Output

512

Why

Unlike every other arithmetic operator in JavaScript, ** (exponentiation) is right-associative, matching mathematical convention where a^b^c means a^(b^c). So 2 ** 3 ** 2 groups as 2 ** (3 ** 2), not (2 ** 3) ** 2. 3 ** 2 is 9 first, then 2 ** 9 is 512. If ** were left-associative like + or *, you'd instead compute (2 ** 3) ** 2 = 8 ** 2 = 64 — a completely different number, which is why this associativity rule matters in practice.

More numbers puzzles

Play today's puzzle →