JavaScript intensive Tutorial-using myths

Source: Internet
Author: User

This article ish5eduAgency officialHTML5 Trainingtutorials, the main introduction:JavaScript Intensive Tutorials--Use mistake

JavaScript usage Myths in this section we will discuss the pitfalls of JavaScript usage. Assignment operator Application Error in a JavaScript program if you use the equal sign (=) of the assignment operator in an IF condition statement, the correct method is to use the two equals sign (= =) of the comparison operator. The IF Condition statement returns False (as we expected) because X is not equal to 10:var x = 0;if (x = = 10)
if  conditional statement returns  true  (not what we expected) because the conditional statement executes as  x  assignment  10,10   true:var x =  0;if  (x = 10) 
The if  conditional statement returns  false  (not what we expected) because the conditional statement executes as  x  assignment  0,0   false:var x = The  0;if  (X = 0) Note Assignment statement returns the value of the variable. Common errors for comparison operators in a general comparison, the data type is ignored, and the following  if  conditional statements return  true:var x = 10;var y =  ";if " (x == y) in the strict comparison operation,===  is the identity of the operator, while checking the expression value and type, the following  if  conditional statements return  false:var  x = 10;var y = ;if  (x === y) This error often appears in the  switch  statement, The switch  statement is compared using the identity calculation character (= = =): The following instance executes  alert  popup: Var x = 10;switch (x)  {     case 10: alert ("Hello");} The following instances do not execute because of type inconsistency  alert  popup: Var x = 10;switch (x)  {    case   "Ten":  alert ("Hello");} Addition and Connection Considerations addition is two numbers added. The connection is a two-string connection. Both the addition and connection of javascript  use the  +  operator. Next we can see the difference between the number of two numbers and the connection between numbers and strings through an example:var x = 10 + 5;           // x The result is  15var x = 10 +  "5";        //  x  results for   "105" Use variable addition results also inconsistent: var x = 10;var y = 5;var z = x  + y;           // z  Results for   15var x = 10;var y =  "5";var z = x + y;            // z  results for   "105"

Click to enter JavaScript intensive tutorial

This article is from the "11721999" blog, please be sure to keep this source http://11731999.blog.51cto.com/11721999/1855287

JavaScript intensive Tutorial-using myths

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.