Javascript Function Creation Calculate Square

Description

Javascript Function Creation Calculate Square

    // w  w w . j  a  v a2 s .  c  om
// square the numbers from 1 to 10
for ( let x = 1; x <= 10; x++ ) 
   console.log( "The square of " + x + " is " + square( x ) + "\n" );

// The following square function's body is executed  
// only when the function is explicitly called.

// square function definition 
function square( y )    
{                       
   return y * y;        
} // end function square                   



PreviousNext

Related