JavaScript basic knowledge The function _javascript skill of blind spot summary

Source: Internet
Author: User

A function is an event-driven or reusable block of code that executes when it is invoked. This article focuses on JS basic knowledge of the blind spot summary function.

Arguments object in a function

There is a arguments inside each function that returns all parameters accepted by the function

Note: The Argumens receives the argument

The following is a sum 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. Scope of variables

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

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

Local variables defined within a function that do not exist outside the function

If the Var statement is not used when declaring a variable inside a function, the variable is default to global (even if it is defined outside of the function). This variable will not exist until the function is called, and the function will be created and given the global scope for the first time after it is called.

Iii. Self-tuning function

A self-tuning function is a function that can be called by itself after a definition, and the basic structure is as follows:

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

The following () can be passed by parameter, and the value declared in it is automatically passed to the parameter of the function

Using such a custom anonymous function as above does not produce any global variables

Iv. functions that can be rewritten by themselves

The feature of this function is that it can be overridden by itself after execution, and here's an example:

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

When a () is invoked for the first time, alert ("a") is executed and alert ("B") is executed the second time a () is invoked. Because when the function is executed for the first time, it is redefined by the global variable A

The above is a small set of JavaScript to introduce the basic knowledge of the blind spot summary of the function of the relevant knowledge, hope that the above help!

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.