Functions organize your code and allow you to reuse data. Functions return a output(value) for the input you put in. An example of a function is shown below. By typing the word function, you name the operation you want the code to perform. In this example we are looking for a sum, therefore, the code reads
function addNumbers(a,b) {
Then you will put:
return a + b;
This tells the code what you want as your output. The function will produce a value for the sum of the number you assign to value a and value b.
If a=3 and b=4
The code will return 7
Then code is closed with }. This is how you properly use a function in Javascript.
Leave a Reply
You must be logged in to post a comment.