Introduction to two common methods of function calling in js _ javascript skills

Source: Internet
Author: User
This article mainly introduces two common methods for calling functions in js. If you need them, refer to the next js function.

Function test (aa) {window. alert ("You entered" + aa );}

Method 1: directly call

Test ("dddd ");

Method 2: assign a value to a variable

Var abc = test;

Abc ('China'); // call a function using variables

Note:

When we write this form, var abc = test ("dddd"); the function cannot be called through the abc variable.

In this way, when test has a return value, it will assign the return value to abc. When there is no return value, the value of abc is undefine.

In particular, JavaScript naturally supports variable parameters.

// Write a function that can accept any number and calculate their sum // It cannot be overloaded. The abc2 function name cannot be repeated function abc2 (n1) {// you can ignore the n1 parameter // There is an arguments in js that can access all input values. // Window. alert (arguments. length); // traverse all parameters for (var I = 0; I

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.