Java script functions, variables, objects

Source: Internet
Author: User

Java script function

Function: A reusable code that is executed by an event-driven or when it is called.
Function names are strictly case-sensitive and duplicate names produce overrides.

1. function with return value
Sometimes, we want the function to return the value to the place where it was called.
This can be achieved by using the return statement.
When you use the return statement, the function stops execution and returns the specified value.

2. Local JavaScript variables
A variable declared inside a JavaScript function (using VAR) is a local variable, so it can only be accessed inside the function. (The scope of the variable is local).
You can use local variables with the same name in different functions, because only the function that declares the variable can recognize the variable.
As soon as the function is complete, the local variable is deleted.

3. Global JavaScript variables
Variables declared outside of a function are global variables, and all scripts and functions on a Web page can access it
4. The lifetime of JavaScript variables
The lifetime of JavaScript variables begins at the time they are declared.
Local variables are deleted after the function is run.
Global variables are deleted after the page is closed.

5. Calling functions with parameters
When you call a function, you can pass a value to it, which is called a parameter.
These parameters can be used in functions.
Variables and parameters must appear in a consistent order. The first variable is the given value of the first parameter passed.
Alert (Window.calc (3,5)); window is the largest variable

<! DOCTYPE html>

  

<! DOCTYPE html>

  

Java script functions, variables, objects

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.