Variables as parameters functions

Hi I’m new to JS and coding, so apologies in advance for a rookie question, but is it possible to use variables as parameters? Thanks guys.

Yes it is possible. here’s an example

let variable1 = "hello";

function alertTheUser(message) {

alertTheUser(variable1); //alerts with text hello

It will just find the variable and see the value of the variable and use it. You can put a lot of stuff inside a parameter. You can put functions as parameters. You can learn more of it here:

Thank you! I really appreciate the annotated code as well! I’ll read through W3Schools as it seems like they have a lot on the basics of code!

1 Like

The quality of the information on W3Schools is hit-and-miss (although it’s much better than it used to be), but the “try it yourself” widgets are great for fiddling with small amounts of code.


Thanks for the tip, Next time I’ll try to link a MDN page. :slight_smile:

1 Like

I wasn’t trying to criticize! I just wanted to give @donchan91 a heads-up that their mileage may vary depending on what they’re looking up. :smiley:

1 Like