Javascript variable supplement

Source: Internet
Author: User

The previous article wrote about JS variables. js variables are also written here. Example:

 
<SCRIPT type = "text/JavaScript"> var STR = 'abcde'; var OBJ = new string (STR); function newtostring () {return 'Hello world! ';} Function func (VAL) {Val. tostring = newtostring;} // Example 1: input value func (STR); alert (STR); // Example 2: Input reference func (OBJ); alert (OBJ ); </SCRIPT>
 
TIPS: func (XXX); is the modification value.

In this case, you can look at the similar example above:

VaR A = 3.14; // declare and initialize a variablevar B = A; // copy the variable's value to a new variablea = 4; // modify the value of the original variablealert (B) // displays 3.14; the copy has not changedvar A = [1, 2, 3]; // initialize a variable to refer to an arrayvar B = A; // copy that reference into a new variablea [0] = 99; // modify the array using the original referencealert (B); // display the changed array [99,2, 3] using the new reference

Variable Declaration

There are two methods for variable Declaration: explicit and implicit.

Explicit usually refers to the use of VaR declaration, implicit (I .e., Declaration)

 
// Declare the variable var str = 'abc'; // declare the function Foo () {STR = 'abc';} // nanming exception object extry {//...} catch (Ex ){//...}

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.