var x = exampleFunction(1, 4);

In the above snippet, we are setting the value of x to the returned value of the ‘exampleFunction’; we pass the function the values 1 and 4, these then become par1 and par2 when inside the function as they are passed through from the parenthesis through to the code inside the curly braces. In this example, the code then adds the two values together and returns the result. After this line of code is run, the variable x will be equal to 5.

Functions are completely reusable. We can define it once and use it as many times as we like, passing in different values each time to suit our needs. This is the magic of programming – you can write a function just one time and use it throughout your entire website to speed up your development time and keep things consistent.