I encountered a problem when writing a class library that simulates the js information box today. I hope that when I do not pass the parameters past, "prompt information" is automatically used as the window title. I'll try to write this
The code copy is as follows:
function MessageBox(title=""){
}
There is no doubt that I failed to run (or I wouldn't have posted this blog post)
Finally, after Baidu, I found such a good thing
The code copy is as follows:
function test(a){
var b=arguments[0]?arguments[0]:50;
return a+':'+b;
}
According to my understanding of my madness, arguments are probably something similar to an array. The subscript starts from 0 and represents the parameters of the function in sequence.
For example, arguments[0] in the above example represents parameter a
In fact, arguments[0]?arguments[0]:50 can also be written as: arguments[0] || 50; The writing style is quite concise. The above is the method of setting the default value of function parameters in js