Home  >  Article  >  Web Front-end  >  JS custom function with default value_javascript skills

JS custom function with default value_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:04:43915browse

I started to take it for granted that it might be like
js code in languages ​​​​such as php or python.

function test(a,b="er"){ alert(a b ); } However, after the definition, it keeps reporting an error: missing object .After inquiry, I found that it cannot be defined like this in JavaScript. You can take advantage of the fact that arguments is a real parameter group. Please refer to the following example: js code



Copy code

The code is as follows:



After testing, it worked. It seems that everything has its own rules and cannot be taken for granted. Write it down here so you don’t make the mistake again later.
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