In JavaScript, we use functions to create things and perform tasks. It is an organizational tool that creates a maintainable, reusable code. Functions work to combine code together to create something and allows for it to be easily found. It groups things together and makes your code able to be used again. They are a vital part of creating any code. The function must have a name attached to it like the one from our example in class, ‘function showDistance()’. Then they contain information about what is going to happen in this function, ‘(speed, time)’. And then with this data we attach the value to it by alerting how this information will be used, ‘alert(speed * time);’. By using something called a function call, we can input actual values to this equation that we have created through our function and get real answers. This real answer is “returned” as the value of “distance” in this case. Functions are so important to creating a simple way to determine what it is you are looking to find out, or looking to create through your code. The way it is reusable is because you can attach new values to the function call and do it multiple times, getting all the answers you are looking for.
Reader Interactions
Comments
Leave a Reply
You must be logged in to post a comment.
Hi Madison, functions are a key component when creating a code. Functions allow you to be able to break a code down into smaller, more easily manageable pieces. You did a good job explaining why functions are important, and how you construct one.
I like how you used the example from class to explain the use of functions in Script