Unary operators:
1. Increment + + decrement--
var userage = 25console.log (///25-remains as-is userage,//26-Adds 1 on the original base and returns ++userage,//25-minus 1 on the original basis and returns --userage,///25-return first and then subtract one userage++ on the original basis,//26-line return and subtract one userage--on the original basis)
2. Front-facing difference
Note: In the absence of an assignment operation, the front and back are the same, but in the assignment operation, the front is added and then returned, and the
3. Other types of effects
String-can be converted to a numeric value, returning 90var TestValue = ' 89 '; Testvalue++;console.log (TestValue)//String-cannot be converted to a numeric value, return nanvar testvalue = ' ff '; Testvalue++;console.log (TestValue)//Boolean-can be returned as a numeric value, return 1var TestValue = false; Testvalue++;console.log (TestValue)//number-can be converted to a numeric value, return 3.15var TestValue = ' 3.14 '; Testvalue++;console.log (TestValue)//Object-supports conversion to numeric value, returns 2var TestValue = {valueof:function () {return 1}}; Testvalue++;console.log (TestValue)
Positive and negative operators:
String-Auto implicitly converts to numeric type, failed to return nanvar TestValue = ' console.log '; +testvalue,-testvalue) var testvalue = ' ff '; Console.log (+ TestValue,-testvalue)//Boolean-can be converted to a value of 1, return 1, -1var testvalue = True;console.log (+testvalue,-testvalue)//number-can be converted A value of 3.14, return 3.14, -3.14var testvalue = True;console.log (+testvalue,-testvalue)//Object-Support conversion to numeric value, return 1314, -1314var TestValue = {Tostring:function () {return 1314}};console.log (+testvalue,-testvalue)
Arithmetic operators:
1. Addition
Description: + In the numeric operation of the addition, in the concatenation of the string is a concatenation, so from left to right add string when the string is automatically stitched
Number + Number returns the value Var testvalue = 1 + 2;console.log ( TestValue)// Any value + NaN return nanvar testvalue = 1 + nan; Console.log (TestValue)// infinity + infinity return infinityvar testvalue = number.positive_infinity + number.positive_infinity;console.log (TestValue)// - infinity + -infinity return -infinityvar testvalue = number.negative_infinity + number.negative_infinity;console.log (TestValue)// infinity + -infinity Return to Nanvar testvalue = number.positive_infinity + number.negative_infinity;console.log ( TestValue)// number + boolean return value var testvalue = 100 + true; Console.log (TestValue)// number + string return string var testvalue = 100 + ' Console.log ';// number& (TestValue)nbsp;+ number + string first calculates the value and then goes to the string var testvalue = 100 + 100 + ' Console.log ' (testvalue)// number + object Returns the method Var of the dependent object valueof () and ToString () testvalue = 100 + { tostring: function () { return 100 }};console.log (TestValue)
2. Subtraction
Description:-No ambiguity, so will automatically convert both sides of the operand to a number and then the operation principle of the same
3. Multiplication
Description:-No ambiguity, so will automatically convert both sides of the operand to a number and then the operation principle of the same
3. Division
Description:-No ambiguity, so will automatically convert both sides of the operand to a number and then the operation principle of the same
4. Take the mold
Description:-No ambiguity, so will automatically convert both sides of the operand to a number and then the operation principle of the same
Relational operators:
Description: The operator used for comparison as a relational operator (< <= < >= = = = = = = = =!==) operator
Var username = {}var userage = {}console.log ( // The two operands are numeric, the value is compared, the return Boolean 2 > 1, // two operands are all strings, Returns the Boolean value ' Limanman ' > ' Liuzhenzhen ', , as compared to the ASCII value of the sequential string // one of the operands is a numeric value, and the other operand is a string of non-pure numbers that is converted to Nan, so the comparison with any numeric value is false ' 1314A ' > 1314, // if one of the operands is an object, first call the valueof () method or the ToString () method, and then use the result comparison ' 521 ' > { tostring: function () { return 520 }, }, // in any case where conversion is not required, null and undefined are equal, because undefined inherits from null null == undefined, // when one of the operands is Nan, returns FALSE&N regardless of the other operandbsp; nan == nan, // types are equally judged on the basis of equality of values can be used === null == undefined, /* each new object refers to a different address, and can be used to determine whether to reference from the same address * can use var userage = username to ensure that they are referencing the same object address */ username == userage)
Logical operators:
Description: Logical operators are typically used for Boolean operations, typically with relational operators, with three logical operators (And/or/not), which are short-circuiting and return values as final judgments
1. Operands on both sides of a logical operation if it is an object, the object returns to true permanently, so that when the operation returns another operand, or the operation returns the object itself
2. Operands on both sides of a logical operation if there is a Nan or null or undefined return nan/null/undefined
3. Logic can not be used for any value, regardless of the value of what type, this operation will return a Boolean value, for nan/null/undefined return is true, logic can not be used more than once, the results of many previous times reversed
Logical operators - objects cross to True Var userinfo = { tostring: function ( ) { // even when return null, the logical operation is true return null }}console.log ( // Note that: returns the value of the expression on both sides of the && is not a Boolean value, which returns 1314 userinfo && 1314, // note: &&, only to judge false, that is, to know the result, so directly return to False false && userInfo, // Note: | | , you need to judge userinfo to know the result, so return to userinfo false | | userInfo, // Note the first: operand is nan or null or undefined, returning nan/nall/undefined null && undefined, null && nan, undefined && null, undefined&nbsP;&& nan, nan && undefined, nan && null, // Note that: can reverse any data type, and it supports two times inversion,!null, ! nan, !undefined return true !null, ! nan, !undefined)
Bitwise operators:
Description: Bit operations are based on the underlying, performance and speed are very good, but the difficulty is relatively large, bit operations include non (~), bit with (&), bit or (|), Bit XOR (^), left Shift (<<), right Shift (>>), unsigned Right shift (>>>)
overstating: http://www.zhihu.com/question/38206659 , the artifice of bit operations
Assignment operators:
general assignment var testvalue = 100//Compound assignment TestValue + = 100testValue = 100testValue *= 100testValue/= 100testValue%= 100testValue <<= 100testValue >>= 100testValue >>>=100
Other operators:
1. String operator, string operator only one, ' + ', the function is to add two strings, at least one operand is a string
2. Comma operator, you can perform multiple operations in one statement
3. Ternary conditional operator, in fact, is the abbreviated form of the IF statement
string operator var TestValue = + ' Console.log (testvalue)//comma operator var i = ten, j = 20console.log (i, j)//ternary operator Var TestValue = 2>1? " To ":" Error "Console.log (TestValue)
This article is from the "ζ Automated operation and maintenance development Road ζ" blog, please be sure to keep this source http://xmdevops.blog.51cto.com/11144840/1846123
Website Front end _javascript.0005.javascript operation expression