Javascript variable fields cannot be displayed

Source: Internet
Author: User

Alert (cc). I don't know why it cannot be displayed.

Reference content is as follows:
<Script language = "javascript">
Function aa (bb ){
Bb ++;
}
Function zz (){
Var cc = 1;
Aa (cc );
;
}
Zz ();
</Script>

It is expected to be 1.

Reference content is as follows:
<Script language = "javascript">
Function aa (bb ){
Bb. setDate (bb. getDate () + 1 );
}

Function zz (){
Var cc = new Date ();
Aa (cc );
;
}
Zz ();
</Script>

Why does cc Add a day?

  Correct answer:

  The key lies in your var cc = new Date (); this sentence seems to have indeed defined a local variable cc, but this is not the case; the fact is that the CC defined here is a date object instance. To illustrate this, you can use typeof (cc) to check the type, and you will find that the returned type is the object type. Therefore, the answer is clear. Now that the object type is used, the aa method called here is the same as passing an object instance in a frequently used advanced language.

Afterwards: You can also check the code output by alert 1, which should return the value type rather than the object type.

Related Article

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.