+ 1
What are javascript function parameters and how do I use them?
I've always been confused on these, and I'd like to learn how to use them. I've gone through the 'Function Parameters' lesson, but it only teaches about where to put them and putting a string as the parameter. What about parameters that aren't strings?
4 Answers
+ 3
you can use non-string as parameter, its same as the example that use string.
but if you want your function only accept non-string, you can add a safe guard in the function, for exampe you can use function like isNaN
function numberOnly(x){
if(isNaN(x))return;
//do something with x
}
+ 3
Ally Whitmer How would you describe function parameters in your own words? This will help me understand where you might be struggling with the concept.
+ 1
parameters are like local variables. in the actual function call arguments replace the parameters...
ex.
function add(x, y) {
return x+y;
}
//x and y are parameters holding space for future arguments.
add(1,2);
add function returns 3