0

# Function Parameters

What exactly are function parameters? How do they work? I know there's more to parameters than just this: function Test(a, b) { alert(a + b); ) Test("Hello ", "World!"); Take this code I wrote for example: https://code.sololearn.com/WsEXgBv9x9Xx/?ref=app I have no idea what a and b are in the second function. The point is, I know very little about parameters and they have me confused when I see them in complex Javascript.

3 Answers

+ 3

sort function uses compare function to make comparison in the sort algorithm. 2 compare input parameters are needed, must be a and b. if return a-b will generate ascending order sorted array, else if return b-a will generate descending order sorted array.

0

Function :
Function are used to reduce code in your program.
For example :
Suppose your program is based on adding numbers.
Instead of doing addition every time , you can define function once and call it as many times as you want.
Examples :
function add(a,b)
{
console.log(a+b);
}
add(1,2) //ans 3
add(5,9) //ans 14
and so on...
Hope this helps you.

0

But what exactly is a and b in the sort function?
Parameters are so confusing to me xD