Javascript Learning Notes

Source: Internet
Author: User
Tags type casting

Javascript Note

Chapter one 1.1 values       JS has six basic value types: number,string,boolean,object,function,undifined1.2 The number computer uses a sequence to store data in memory, JS uses a fixed-length bit sequence of 64 to hold numeric values, and for binary, 64 bits can represent 2^64 numbers but are not actually that large because the 64-bit sequence needs to represent a negative number, So there is a sign bit used to denote the positive or negative of the number, and some bits are needed to store the information of the decimal point (not specified in the book, a bit complicated to learn) due to the mechanism of the computer processing floating-point numbers, the calculation results will be very accurate, but the calculation of decimals will have a loss of precision, So the computed decimals are approximate 1.2 arithmetic PS: No need to memorize the priority of the operator, the uncertainty only need to bold plus braces () 1.2.2 Special number +/-infinitynan non-numeric value in Infinity-infinity, 0/ 0 and so on will appear 1.3 strings in JS "", "" is surrounded by the string PS: The special case is that there is "" "in the string to use the escape character (as in Java)------' \ '   if \ n for line break such as" Fuck ' \ n ' "needs To write   "Fuck \" \\n\ "  You can use ' + ' to concatenate multiple strings 1.4 unary operators      such as typeof   sizeof1.5 Boolean with only two values of true FA LSE pay particular attention to the comparison mechanism of strings (java.lang.String is not allowed to use <, > and other operator to compare), in JS is the Unicode value (the first letter) to compare the essence is the Unicode value to compare http:/ /www.imkevinyang.com/2009/02/%e5%ad%97%e7%ac%a6%e7%bc%96%e8%a7%a3%e7%a0%81%e7%9a%84%e6%95%85%e4%ba%8b%ef%bc% 88ascii%ef%bc%8cansi%ef%bc%8cunicode%ef%bc%8cutf-8%e5%8c%ba%e5%88%ab%ef%bc%89.html1.5.2 logical operators (&&,| |,!)note the operator precedence problem, simple | | Priority, followed by && then comparison operator (<,>,==)* ternary operator? :1.6 undefined nullJS Unique undefined (feeling is) in JS and null difference is not small 1.7 automatic type conversion JS will automatically convert the value of the operator at both ends to the type of their own expectation, called Type Casting
1 console.log (5 + "6");
<!--56-->2 console.log (5-"3");
<!--2-->3 console.log (5 + ' 1 ');
<!--51-->4 console.log (5 * ' 2 ');
<!--10-->
However, some values JS cannot be converted, such as Nan, a string, this will produce a nan, the result of the operation containing Nan is still nan,
When comparisons are made using "= =" between values of the same type, the result of the operation is well predicted (as long as there is no nan at both ends, as long as two values are the same, return true),
1 console.log (NaN = = 5);
<!--false--2 console.log (NaN = = undefined);
<!--false--3 console.log (NaN = = "");
<!--false--4null);
<!--false--
In addition, when using a value and a Boolean false comparison, the JS comparison rule is, 0, "", NaN is equivalent to false, others are equivalent to true if null or undefined exists at both ends of the operator, then only both ends are null or undefined is trueby the way, strictly the comparator ' = = = ', the requirement is exactly the same to return True
Console.log (null = = undefined);
<!--true-->
Console.log (Null = = = undefined);
<!--false-->

 

Since the value types at both ends of the operator are different, JS's conversion rules are comparedComplex, make sure that the value types are consistent in advance, and that the use of equality operators will have unintended consequences for subsequent code, and the answer is likely. #程序结构 # #control Flow # # # If Elsejs is a bit different from Java syntax is if () Dowork;else if () dowork;elsedowork; #章节习题

Javascript Learning Notes

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.