JavaScript jumping forward (1)-Basic concepts

Source: Internet
Author: User
Tags bitwise bitwise operators hasownproperty

Objective

JavaScript is a weakly typed language that is 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. Case-sensitive [very important, such as true and false are not booleans, but identifiers]
    2. And strong type basically much the same, with strong type of naming style basic nothing wrong; recommended Hump case
    3. Comments have single-line and multiline comments
    4. Strict mode, the speed of operation is the fastest; but quite a lot of things are limited.
    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 are not allowed to do variable names [specific check list go to it. Many
Data type

There are some data types : undefined (undefined), null (null value – Special value), Boolean (Boolean), number (numeric), string (String), object (the range is quite wide, and the array belongs to it). )

    • Undefined: Default value for variable uninitialized
    • Null: is a special object [empty object reference]
    • Boolean: 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: Also unlike a strongly typed language, a numeric overflow of Infinity,[nan is a special value, depending on whether a decimal point is defined with a value to define a floating point or an integer.
    • String: Strings
    • Object: The function is the objects. In JS, the function returns an object by default when there is no return value
Data judgment

typeof, Instanceof, hasOwnProperty, isprototypeof, IsArray

    • typeof: Most types will be classified as objects
    • Instanceof: Used to determine whether a variable is an instance of an object
    • hasOwnProperty: is used to determine whether an object has a property or object that you give a name to. However, it is important to 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 determine whether the object whose prototype chain is to be checked exists in the specified object instance, or True, otherwise returns false.
    • Isarray:es5 adds a special judgment on whether an array
Data conversion
    • Number (): You can convert content that is allowed to be converted to a numeric value, such as the string "123" [0 ignored], an empty string of 0, and a character other than a number can 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 operators: Includes subtraction, pre-minus + and post-decrement Gaga [pre-set-first-assignment-effective re-execution, post-execution and re-operation]
    • Bitwise operators: Consistent with strongly typed languages, including bitwise non (~) [value inverse, true/false], bitwise AND (&) [same as true, others false], bitwise OR (|) [True is True, 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 because the 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 allowed to convert to a comparison type, automatic conversion of matching type comparison], = = = [Strong, no conversion comparison, while comparing types and values]
    • 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.