+ 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?

27th Jun 2019, 2:38 PM
Ally Whitmer
Ally Whitmer - avatar
4 Antworten
+ 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 }
27th Jun 2019, 3:28 PM
Taste
Taste - avatar
+ 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.
27th Jun 2019, 3:55 PM
David Carroll
David Carroll - avatar
+ 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
6th Aug 2019, 1:56 PM
kay cruz
kay cruz - avatar