JS Basics 4-Arrays and operators

Source: Internet
Author: User

One, array

An array uses a separate variable name to store a series of values,

JavaScript provides an array with a length property to get the lengths of the arrays.

The JS array has the following features:

1. The array length is variable. The total length equals the maximum index value of the array +1

2. Element types in the same array can differ

3. when an unassigned array element is accessed, the element value is undefined and the array is not out of bounds

<script>    var arr1=[2,5,6];   Assign a value to the array element    var arr2=[] when defined;   defines an empty array    var arr3=new Array ();   defines an empty array and assigns values by index    arr3[0]=1;    arr3[3]= "abc"; </script>
Array

Second, operator

  + +: self-added : +1 of the original data

  --: self-subtraction : 1 of the original data

For example:

We look at the equation from left to right in the blending operation.

first in variable x The value of span class= ">x ( int y = 3 + ++x + x * 10), +1; Here the variable x = 3+1 = 4, ( If not understood can make int a = X + +, a = 3);

then go to the right to see ++x,+ + in front of the variable x , the first self +1 ( that is , x = 4+1 = 5), then the value is then placed in this position (int y = 3 + 5 + x *)

last x *, at which point x = 5, int y = 3 + 5 + 5 *;

The end result is x = 5;y = 58;

Type

Operator

Arithmetic operators

+   -    *   /   %   ++   --

Assignment operators

=

Comparison operators

> < >= <= = = = = = = = =!===

logical operators

&& | | !

Bitwise operators

& | ~ ^ << >>

Other operators

Trinocular operator (?:), comma operator, void operator, typeof, instanceof

<!doctype html>//var a=52%10//document.write (a);//Take the remainder//var b=2;//var c=3;//B>c?alert ("established"): Alert ("not established");//Three mesh operator//var a,b,c,d;//a=void (b=5,c=2d=3);//alert (a);//void operator    varA=[12]; Alert (typeof(a));//returns the data type of the variableAlert (AinstanceofArray); Alert (AinstanceofObject); </script>operator

JS Basics 4-Arrays and operators

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.