0
What is functions
2 ответов
+ 4
A piece of code that you can call as often as you need it. e.g you want a simple function that squares a number. So you put this code at the top or at the bottom of your script:
function square( number ){
return number*number;
}
Now you can call it as often as you want:
var number1 = 10;
var number2 = square( number1 );
alert( number2 );
This will alert 100.
+ 2
"A JavaScript function is a block of code designed to perform a particular task.
The main advantages of using functions:
Code reuse: Define the code once, and use it many times.
Use the same code many times with different arguments, to produce different results"
This was copied directly from the course.