JavaScript basic knowledge Blind spot summary--function

Source: Internet
Author: User

The arguments object in a function

There is a arguments inside each function that returns all the arguments that the function accepts

Note: The argumens is receiving an argument

The following is a summation function written using the arguments attribute:

function Sumonsteroids () {var I, res = 0;var Number_of_params = arguments.length;for (I = 0; I < Number_of_params; i++) {    res + = Arguments[i];} return res;}

Ii. about the scope of variables

In JavaScript, you cannot define a specific block-level scope for a variable, but you can define the function domain to which it belongs.

Global variables in JavaScript refer to variables declared outside of all functions

A local variable defined inside a function that does not exist outside the function

If you declare a variable inside a function without using the VAR statement, the variable is defaulted to the global variable (even if it is externally defined in the function). This variable does not exist until the function is called, and is first created and given the global scope after the function is called.

Three, self-tuning function

A self-tuning function is a function that can be called itself after the definition, with the following basic structure:

{function (name) {    alert (' Hello ' + name + '! ');}} (' Martin ')

Subsequent () arguments can be passed, and the values declared inside are automatically passed to the parameters of the function

Using such self-tuning anonymous functions as above will not produce any global variables

Iv. functions that can be rewritten on their own

This function is characterized by the ability to perform a function rewrite after execution, and here is an example:

function A () {alert ("a"); a = function () {    alert ("B")};}

The first time a () is invoked, the alert ("a") is executed, and the second time A () is invoked, the alert ("B") is executed. Because the function was first executed, it redefined the global variable A

JavaScript basic knowledge Blind spot summary--function

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.