Sum of squares of first n natural numbers | Function to calculate sum ; Driver code
function summation ( n ) { let sum = 0 ; for ( let i = 1 ; i <= n ; i ++ ) sum += ( i * i ) ; return sum ; } let n = 2 ; document . write ( summation ( n ) ) ;