Arithmetic operators+ - * / % () Abnormal situation 1: Operations involving special value literals
5/Infinity=0 5%Infinity=5 Infinity%5=NaN Infinity+5=Infinity Infinity / Infinity = NaN Infinity - Infinity = NAN Infinity % Infinity = NAN Special value operations are not used in work and have no practical application significance, but you should understand them in case you encounter them in interviews. Abnormal situation 2: Other types of data participate in mathematical operations.+ operation involving strings (including the case where there are characters only on one side of the symbol): the + sign becomes a hyphen to connect the front and back to form the entire string. For example: var a = 3 - "36" % 5 + "2" - 2 console.log(a) var b = "36" % 5 console.log(b) var c = 3 - "36" % 5 + "2" console.log(c) Output:
Implicit conversion: Except for the + operation involving strings, in other cases, when all other data types participate in mathematical operations, the computer automatically converts other data types into numeric types before participating in the operation. There is no need to use methods such as parseInt() and Number() in this process. The process is carried out secretly. This is an implicit conversion process. Implicit Conversion Other data types are implicitly converted to numeric types:
Comparison OperatorsAlso called relational operator. A comparison operator compares its operands and returns a Boolean value. The result of the operation is either true or false.
Abnormal case 1: Special values participate in comparison operations
Infinity == Infinity -> True Infinity === Infinity -> True Infinity > Infinity -> False Infinity >= Infinity ->True Abnormal situation 2: Other data types participate in comparison operations (excluding string-to-string comparisons)Other data types are also implicitly converted to numbers for comparison. “123”→123 true→1 false→0 null→0 undefined→NaN “”→0 “abc”→NaN The judgment of null is special: when null and 0 are judged, equality is false, >= and <= are true null == undefined -> True Abnormal situation 3: string to string comparisonNo implicit conversion to numbers occurs, but the two strings are compared in Unicode order. Character encoding order: from front to back 0-9, AZ, az, the front one is smaller than the back one When comparing, the length of the two strings is not important. The comparison starts from the first character and continues until the size is determined. No more comparisons are made. Logical operatorsLogical operators are often used between Boolean values; when the operands are both Boolean values, the return value is also a Boolean value.
Abnormal situation
Rules for implicit conversion to Boolean values
When they are used on non-boolean values, the return value may be a non-boolean value. In fact, this operation is very simple:
Logical operator order of operation Comprehensive operation order: NOT, AND, OR Assignment Operators
Unary Operators
++ or -- symbols can be written before or after a variable. Different positions may result in different program execution results. Take ++ as an example:
Example 1 var a = 3; var b = a++; var c = ++a; console.log(a,b,c) Output:
Example 2 Output: Operation priorityPriority from highest to lowest:
example var a = 4; var num = 1 * (2 + 3) && a++ || 5 > 6 && 7 < 8 || !9; console.log(num) Output:
SummarizeThis concludes this article on the summary of operator calculations in JavaScript that are prone to errors. For more relevant JavaScript operator calculation content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL 8.0.18 installation and configuration method graphic tutorial
>>: Detailed explanation of several commands in Linux to obtain detailed hardware information
Background requirements: As the business grows la...
Correspondence between flutter and css in shadow ...
Recently, several data anomalies have occurred in...
1. What is a calculated attribute? In plain words...
illustrate: Using mysqldump –all-databases will e...
I recently came into contact with MySQL. Yesterda...
<br />For an article on a content page, if t...
Table of contents 1. Overview 2. Use docker to de...
Error message: user: 'root' host: `localh...
This article example shares the specific code of ...
1. Delete file command: find the corresponding di...
First, let me explain that what we want to do is ...
Often when building a SPA, you will need to prote...
Designers need to understand psychology reading n...
Table of contents 1. Stop MySQL Server first 2. U...