I have a parameter znah_1. I need it to have default parameter values.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

1 answer 1

It’s not quite clear from your question, but if you mean the default value of a parameter for a function, then.
ES5, Method 1:
Honest way. The parameter that did not come, therefore must be set to the default value of undefined.

function myFunc(znah_1){ znah_1 = typeof znah_1 !== 'undefined' ? znah_1 : '666'; // 666 - my default value } 

ES5, Method 2:
The most common way. We use the fact that the operator or returns the leftmost argument, which is not reduced to false. But you have to understand that if you need to somehow work out the input parameter that leads to false, but not undefined (false, null, '', 0), then you can't do that.

 function myFunc(znah_1){ znah_1 = znah_1 || 666; // 666 - my default value } 

ES2015:
Simple and intuitive.

 function myFunc(znah_1 = 666){ // 666 - my default value }