JavaScript Function

Function Definition Described

nick3499
1 min readMar 18, 2017
function add ( x, y ) {
return x + y;
}
c = add ( 20, 35 );
console.log ( c );

function add (x,y) is the function definition. function is the keyword. add is an optional function name. Otherwise, it may remain anonymous. (x,y) contains comma-separated parameters which will be defined as variables, and initialized to given arguments. In this case there are two, representing two numerical values. Some functions will have empty parentheses. {return x+y;} contains the body of the function or statements. c = add (20,35); invokes the function. console.log(c); prints the result to the console, which reads 55.

--

--

nick3499
nick3499

Written by nick3499

coder of JavaScript and Python

No responses yet