JavaScript understands the concept and role of 04-? functions

Source: Internet
Author: User

 the concept and function of functions

function is a core concept for any language.   by function you can encapsulate any number of statements,   and can be invoked anywhere, at any time, that is, a function is defined once but can be called or executed Any number of times  js code Span style= "; font-family: Microsoft Jas Black; font-size:14px" >

JS function is also an object, so JS functions can be manipulated and passed like other objects, and we often call JS the functions in as a function object.

The writing of functions

ECMAScript use the function in the function keyword to declare, followed by a set of parameters and the body of the function.

The concept types and functions of events

N event is a specific interaction moment that occurs in a document or browser window. You can use listeners (or handlers) to subscribe to events so that the appropriate code executes when the event occurs.

A focus event that triggers when an element gains or loses focus;

Mouse events, which are triggered when the user performs an action on the page with the mouse;

Keyboard events that trigger when a user performs an action on a page through the keyboard

......

N onclick/ondblclick/onmouseover/onmouseout/onkeydown/onkeyup ...

The relationship between events and functions, and the combined use of

function and loop combine to print 99 multiplication table

Benefits of the function (reference concept)

Two ways to create a function: declarative and assignable

JS compilation and execution

JS The parsing process is divided into two stages: the pre-compilation period ( pretreatment ) and the implementation period.

pre-compilation period JS all declared variables and functions in this code block are processed (similar to the C language, but it is important to note that the function is only declared at this point, and the variable is only declared but not initialized and assigned. The execution period is the start of the script from top to bottom on a post-compilation basis and interrupts when an error is encountered.

Declaration elevation of a variable

formal parameters and arguments

ECMAScript The function does not mind passing in the number of parameters, nor because the parameters are not uniform and error. In fact, the body of the function can receive the passed in arguments (arguments) through the arguments object

return keyword

most functions have areturnstatement,returnstatement causes the function to stop executing and return the value of its expression to the calling The user. Ifreturnstatement does not have a related expression, it returnsundefined.

Scope

any programming language has the concept of scope, simply speaking, scope is the scope of the variable and function, that is , domain controls the visibility and life cycle of variables and functions. In JavaScript , the scope of a variable has both global scope and local scope.

Recursive functions

A recursive function is formed when a function calls itself by name.

anonymous functions and Invocation methods

Constructors and object types (understanding)


JavaScript understands the concept and role of 04-? functions

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.