JavaScript Learning 1

Source: Internet
Author: User

<script type="Text/javascript">vara,b,c,d; A= (b=5, c=2, d=3);//comma operator: it only returns the value of the last-side expressionConsole.log (a);//3                 vara,b,c,d; A=void(b=3, c=2, d=3);//Void emphasizes that subsequent expressions do not return a value to aConsole.log (a);//undefined                 vara=[1,2]; Console.log (a instanceof Array);//A is an instance of the array trueConsole.log (a instanceof Object);//All objects are an instance of an object</script>

For (variable in object) {
The block of statements executed;
}
Role:
1. Iterate through all the array elements in the array.
2. Traverse all the properties of the JavaScript object.

<script type="Text/javascript">varArr=NewArray (5);//Although the length of the array is defined as 5, it is possible to assign values backwardsarr[0]=1; arr[2]=3; arr[3]="ABC"; arr[5]=true;  for(varIndexincharr) {        /*Console.log (index);//0 2 3 5*/Console.log (Arr[index]);//1 3 ABC true    }                      for(varPropertiesinchNavigator) {Console.log ("Properties:"+properties+", property value:"+navigator[properties]); }</script>

Exception Throw statement

<script type="Text/javascript"> for(varI=0;i<Ten; i++) {document.write (i+"</br>"); if(i==5){            Throw NewError ("an error.");//See the error effect on the console        }    }    </script>

Exception Capture Statement

<script type= "Text/javascript" >try{var age=5;if (age==5) {  throw new Error ("Too Young");}} catch (E) {document.write ("error:" +e.message);} Finally{document.write ("a finally block that is always executed");} </script>

With statement

<script type="text/javascript">     //withstatement with      ( Document) {        write (" output first row of data </br>");        Write (" output second row of data </br>");        Write (" output third row of data </br>");     } </script>

 

JavaScript Learning 1

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.