Today I encountered a problem when writing a div css class library that simulates a js information box. I hope that when I don't pass parameters, "prompt information" will be automatically used as the window title. I tried to write like this
function MessageBox(title="" ){
}
There is no doubt that my operation failed (otherwise I wouldn’t have posted this blog post)
Finally after some Baidu, I found this Good stuff
function test(a){
var b=arguments[0]?arguments[0]:50;
return a ':' b;
}
According to my humble understanding, arguments are probably similar to An array, with subscripts starting from 0, represents the parameters of the function in order
. 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 method is quite concise. The above is the method to set the default value of function parameter in js.
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn