You are not required to pass it, but the function needs to be handled in case the parameter is not set, otherwise it makes no sense to do so.
For example, we assume a function that displays a greeting message in the console. The function will receive the name it will be greeted with:
function hello(name) {
console.log(`Olá, ${name}`)
}
<button onclick="hello('mandioca')">Saudar</button>
But, see what happens when you do not set the parameter:
function hello(name) {
console.log(`Olá, ${name}`)
}
<button onclick="hello()">Saudar</button>
The function is executed, but a "Undefined" appears, because the parameter has not been defined.
In this case, if it really makes sense to call the function like this, you can assign a default value when the parameter is not set:
function hello(name) {
name = name || 'mandioca' // Se não tiver definido, atribui o valor 'mandioca'
console.log(`Olá, ${name}`)
}
<button onclick="hello()">Saudar</button>
So, when you call the function without a parameter, the function will assign a default value and continue the execution.
You have a function that takes a parameter, but you don’t want to pass a parameter to the function? Is that it? If yes, it will depend on the code you have in "code here". If the function is not handled to not receive the parameter, it will not make sense to call it without it.
– Woss
yes that , I knew it was called parameter rs. And also how do I check if something came in the parameter type if the parameter exists
– Cyber Hacker