A function in JavaScript allows our code to be more maintainable and reusable. In Javascript, a function is a way to organize your code to make it easier to create and reuse. All functions have a name, are passed zeros or more pieces of information, and almost always return a value. A function can also group statements together. An example of a function could be “distance = speed x time”, which we discussed in class. in JavaScript, you would code this function as:
let speed = 10
let time = 7
alert (speed * time);
with would return distance = 70.
To call a function is typically the name the function you want to call (invoke) followed by parenthesis. To pass a function arguments means where your function call contains some data that you pass into the function. To pass a function arguments is used to easily customize a function. Additionally, the return keyword allows you to send data back to whatever called your function to begin with. No code in your function after return will run. Once your function hits the return keyword, it stops everything and and returns whatever value you specified to the caller and exits the function.
I appreciate how you incorporated an example of code into your response in order to show how a function in JavaScript works. It made reading your post much more engaging.