Parameters
Learn about parameters and their types.
We'll cover the following...
We covered functions previously, but now it’s time to dig a bit deeper and look at some more advanced topics specific to JavaScript.
Named parameters
When a function has quite a few parameters, it can be difficult to remember what order to write the arguments in when we call the function. For example, consider this function that returns a styled <div>
element:
Press + to interact
function heading(text, color, size, bgcolor) {return `<h1 style='color:${color};background-color:${bgcolor};font-size:${size}>${text}</h1>`}
This uses positional parameters, which means that when the function is called, the position the argument is placed in determines which parameter it’s assigned to in the function. So, if we wanted a heading of “Hello, World!” sized to 48px and colored red on a blue background, we’d write the following:
...