What is functions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is functions

16th May 2017, 7:24 PM
Hussein Adam
Hussein Adam - avatar
2 Answers
+ 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.
16th May 2017, 7:32 PM
Tim G
Tim G - avatar
+ 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.
16th May 2017, 7:31 PM
Rrestoring faith
Rrestoring faith - avatar