JavaScript authoritative guide Fourth chapter expressions and operators

Source: Internet
Author: User

  1. Expressions: Include constants, variables, array access expressions data = [1, 2, 3].
  2. Operators are common methods of composing simple expressions into complex expressions.
  3. Primitive Expressions: Constants or direct quantities, keywords, and variables.
  4. object, an array of initialization expressions are actually newly created objects and arrays, which are sometimes called "object (array) direct", and an element initialization expression in an array initialization expression can also be an array initialization expression (that is, nested) example: var matrix = [[1, 2, 3], [ 4, 5, 6], [7, 8, 9]]; The elements in the array's direct volume can be omitted: var sparsearray = [1,,,, 5];
  5. An object initialization expression resembles an array: var p = {x:2, y:3}, or it can be nested as follows:
  6. var rectangle = {    upperleft:{x:2, Y:2},     lowerright:{x:4, Y:5}}
  7. Property access expression operations can get an object property or the value of an array element, two syntaxes: Expression.identifier and expression[expression] Examples:
    var o = {x:1, Y:{z:3}}; var a = [O, 4, [5, 6]];o.x                //1o.y.z              //3o["x"]             // 1a[1]               //4
    Note: identifier is used only for the name of the property to be accessed as a valid identifier, and if it is a reserved word, contains spaces and punctuation or a number (array) with "[]".
  8. Operators: Unary, two, ternary (1, 2, 3 operands)
  9. Lvalue: Expression can only appear to the left of the assignment operator, JavaScript variables, object properties, arrays are left values. Note: Property access expressions and invocation expressions take precedence over operators. Eg:typeof My.function[x] (y). Here the TypeOf is finally executed.
  10. "+" operator, "1" + 2//"1" + {}//"1[object Objec]" under two note the sequence of operations: 1 + 2 + "Blind Mice";   "3 Blind Mice" 1 + (2 + "Blind Mice"); "Blind Mice"
  11. + + direct look at the code: (--)
    var i = 1, j = ++i;       // the j,i are all 2 . var i = 1, j = i++;        // i = 2, j = 1  

    The book says ++i is in front of the previous increment, I plus 1, and returns the computed value. While i++ is the post increment, I plus 1, but returns the added value (the original value). My understanding is: + + is the right combination, the reason why ++i return the calculated value because I on the right, is taken into the calculation, and i++, I on the left, no execution here, so return for the added value.

  12. Object conversions are first used with valueof (), and then in consideration of ToString (), all uppercase ASCII letters < lowercase letters.
  13. In operator. The left operand is a string and the right operand is an object. Eg:var point = {x:1, y:2}; "X" in point//true "Z" at point//false
  14. Instanceof: Left is an object ( instance ) and right is the class (function) that represents the object.    Eg:var d = new Date (); D instanceof Date//true All objects are instances of object.
  15. False value: False,null,undefined.0-0,nan and "". Other values include that the object is true. 2015-07-2721:31:02

JavaScript authoritative guide Fourth chapter expressions 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.