JavaScript jumping forward (1)-Basic concepts

Source: Internet
Author: User
Tags bitwise bitwise operators hasownproperty

Objective

JavaScript is a weakly typed language, which is much closer to Python and Perl than it is for Java and C. So the small partners who are accustomed to the strong type language see some alternative writing is quite normal;

Some things are not explaining. After the separate out of the fine talk;

Key extracts: syntax
    1. Distinguish between uppercase and lowercase [very important, for example, true and False are not Boolean values, but identifiers]
    2. And strong type basically much the same, with strong type of naming style basic nothing wrong; recommended hump uppercase and lowercase
    3. Gazing with a single and multi-line gaze
    4. Strict mode, the speed of operation is the fastest, but quite a lot of things to limit
    5. The statement ends with a semicolon, supports the multi-variable definition [comma separated], when the statement is many times, the chain writing speed has certain speed promotion;
    6. Keywords and reserved words do not agree to do variable names [detailed check table go to it. Very much]
Data type

There are these data types : undefined (undefined), null (null-special value), Boolean (Boolean), number (numeric), string (String), object (the range is quite wide, and array is also a part of the Medium), SYMBOL[ES6]

    • Undefined: Default value for variable uninitialized
    • Null: is a special object [empty object reference]
    • Boolean: With only true and false two values, it is worth noting that 0 and 1 do not necessarily mean false and true
    • The NUMBER:JS does not have double precision. Only single precision. Nor is it like a strongly typed language, depending on whether a decimal point is defined with a value to define a floating point or an integer, a value overflow of Infinity,[nan is a special value]
    • String: Strings
    • Object: The function is the objects. In JS, the function returns an object by default when there is no return value
    • Symbol: This is ES6, the general point is a special identifier, can be used to different instances or objects, but not the same as the Lisp symbol (detailed I do not go deep now ~ ~ ~)
Data inference

typeof, Instanceof, hasOwnProperty, isprototypeof, IsArray

    • typeof: Most types will be classified as objects
    • Instanceof: Used to infer whether a variable is an instance of an object
    • hasOwnProperty: is used to infer whether an object has a property or object that you give a name to. Just note that this method cannot check whether the object has this property in its prototype chain, and that the property must be a member of the object itself.
    • isPrototypeOf: is used to infer whether the object whose prototype chain is to be checked exists in the specified object instance, or returns True, otherwise false.

    • ISARRAY:ES5 join is specifically inferred whether an array of
Data conversion
    • Number (): The ability to convert the content of the consent into a numeric value, for example, the string "123" [0 ignored], an empty string of 0, except for the characters that can be converted to a number format will be converted to Nan
    • Paseint (): The conversion string is an integer, if "111ee" will only get 111, character-by-word traversal [if the non-numeric start will not traverse, encountered a decimal point will also stop].
    • Parsefloat (): Converts the string to a floating-point number, similar to the one above
    • Boolean (): Converted to a Boolean value
    • String (): Converts the value to a string, the object transformation calls valueof (), and the ToString () effect is basically the same
Operator
    • Unary operator: Includes subtraction, pre-minus and minus + + and post-decrement +-Gaga [pre-set-first assignment for re-operation, post-run and then operation]
    • Bitwise operators: Consistent with strong type language, including bitwise NON (~) [Value of inverse value, true and False exchange], bitwise AND (&) [with True only true, others false], bitwise OR (|) [The truth is true, the same false is false]. Bitwise XOR (^) [same as false, different is true]
    • Move left and right: move left to power multiplied by 2 and right to the power of 2. Unsigned right shift [positive number unchanged, symbol will become a fairly large positive value due to left padding 0]
    • Logical operators: Logic and (&&) [same as True for true, others false], logic or (| |) [True is True, False is false]
    • Equality operator: = [Assignment, there is a composite operator (can be used with subtraction, such as the operator, such as a%= 3, B *= 2;)], = = [if the consent to convert to a comparative type, their own active conversion of the type of matching], = = = [Strong, not conversion, the same time the comparison type and value]
    • conditional operator [trinocular operator]: (expression)?

      True:false; The expression is true or false to get the corresponding return value

Flow control Statements

Flow control statements, most programming languages are much the same ~ ~ ~

    • If statement
//推荐带花括号,且花括号左边紧贴表达式,能够减少语法解析识别为错误的问题[解析器会自己主动给一些变量或者语句加入分号]if(conditions) {  ... }elseif{ ...}else{ ...}
    • Do-while statements
  //先运行do里面的逻辑,再运行推断表达式来确定下一步是否运行  do{   statement;  }while(expression)
    • While statement
   //适合不知道应该循环多少次的,符合条件就无限运行,带花括号是一个好习惯   while(expression){     statement;  }
    • For statement
  //适合有限的循环for(initialization ; expression ; post-loop-expression){    statement;}
    • for-in statements
  //[ES5]适合来枚举对象的属性,遇到值为null或者undefined则会抛出错误   forin expression){        statement;   }
    • foreach statement
//[ES5] 适合遍历数组,缺点:不能用break跳出循环和用return语句//传统是用for来遍历数组...见仁见智哈var arr = [1,2,3,4];arr.forEach(function(value){console.log(value)})//结果集: 1,2,3,4,undefined
    • for-of statements
   //[ES6]这货的出现,更加方便了数组的遍历...   //它避免了for-in的全部缺陷;   //与forEach()不一样,它支持break,continue和return。   var arr = [1,2,3,4];     for(var i of arr){       console.log(i)   }   //结果集: 1,2,3,4,undefined
    • Label statement
    //跟goto好相似....一般配合break和continue语句;在多重嵌套循环的时候,能够满足条件直接跳出整个循环(标签指定的位置)   for(initialization ; expression ; post-loop-expression){    statement;  }
    • Break and Continue statements
    //break是跳出循环(中断运行)    //continue是跳出这次循环,进入下一次循环(仅仅是跳过符合条件的那一次循环,会继续运行到结束)
    • Switch statement
   //语法和高级编程语言大同小异,适合多重推断(当然不嫌弃麻烦能够用if..elseif...else)   //小提示.若不是要运行多个表达式..记得每一个相应推断条件后必须break结束;否则会依次往下寻找相应的值,其上的全部非包含break的都会运行;   switch(expression){        casebreak;          casebreak;          casebreak;           ...        default:statement;break; }
Function
    • The simplest declarative function
   /*    与大多编程语言一样..函数运行到return语句就结束该函数了..无论后面还有木有表达式;     由于JS是弱类型语言..  在ES6前,有些东西不得不模拟,比方匿名函数,闭包,"花样式"继承       有点值得一提的是,,JS木有重载(当前,以后就不晓得会不会添加)     这里不多说..到时候在新文章拖出来细细揣摩*/    function say(){          console.log("Hello world!");    }    say();    function say1(args1,args2){          console.log("Hello world!");    }    say1();
Summarize

Personally, for my part. Native JS I was tossing the more painful ... Too many tricks to keep on honing

JavaScript jumping forward (1)-Basic concepts

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.