JavaScript: 006-JS Function Definition, JS

Source: Internet
Author: User
Tags js function declaration

JavaScript: 006-JS Function Definition, JS
JS function declaration.
The declaration function format is as follows:

Function Name (parameter list) {// function statement; return value ;}
Let's look at the specific function declaration.
1. Common functions
<Script type = "text/javascript"> function ShowHint () {alert ("common function") ;}</script>
2. Functions with Parameters
<Script type = "text/javascript"> function ShowResult (obj) {// processing statement return false; // return true ;}</script>
Note that for JS functions that generate callback controls such as buttons, the return false is added at the end of the function. If you use return false for some simple operations on the page or just call the JS function of a method in the background, you can avoid frequent page refreshes.
3. Return Value Function
<script type="text/javascript">    function ShowReturnObject() {        Object obj = new Object();        return obj;    }</script>
Returns a JS object.
JavaScript Functions are not complex, but you must note that braces must appear in pairs when writing them. Once a place is missing, troubleshooting is quite difficult for JavaScript code with hundreds or thousands of lines.
Javascript is simple and easy to use, but it is easy to write errors in syntax and difficult to find. Presumably most programmers really love and hate it...
How does javascript call custom functions on other JS pages?

Let me give you an example.
One way is to directly call
<Script> aa (); </script>
There are also some event calls
<A href = '# 'onclick = 'aa ()'> aa </a>
For more information, see the basics .....

How can I directly use javascript function libraries without introducing them? How can I check functions provided by js?

The js function library you mentioned refers to the built-in js objects and methods. Since it is built-in, it is implemented by default by js. As for what you have to learn, for example, the commonly used String, Date, Math, RegExp, and other objects, and Dom objects. To understand JavaScript, we should start with these basic elements.

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.