Skip to content

Exponentiation

JavaScript recursive power

Same task in: C++

Flowchart (ISO 5807)

YesNoStartInput base, expexp = 0Return 1EndReturn base·base^(exp − 1)EndFigure 1 — power

Source code

JavaScript
function power(base, exp) {
    if (exp === 0) return 1;
    return base * power(base, exp - 1);
}

The editor opens with this code — change it and the chart redraws.

Language
JavaScript
Constructs
recursive power
Topic
Recursion
Formats
Word, Visio, draw.io, PDF, SVG

Related examples