JS Set function parameter default value

Source: Internet
Author: User

DIV+CSS simulation of the class library of JS information box encountered a problem when there is no passing parameters in the past automatically use the hint information as the window title, the specific implementation of the following

Today to write a div+css analog JS information box class Library encountered a problem, I hope that when I did not pass the parameters of the past, automatically use the "prompt information" as the window title. I tried to write the code as follows: function MessageBox (title= "") {} No doubt I failed (otherwise I wouldn't have sent this blog) finally passed Baidu, found such a good thing code as follows: function Test (a  ) {var b=arguments[0]?arguments[0]:50;  Return a + ': ' +b; According to my humble understanding, arguments is probably something similar to an array, with the subscript starting from 0, which in sequence represents the parameters of the function, such as the arguments[0 in the example above, which means that argument a actually arguments[0]?arguments[0]:50 Can also be written as: Arguments[0] | | 50; The wording is quite concise. Above, is the method of setting the function parameter default value in JS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.