JavaScript Common Mistakes

Clash Royale CLAN TAG #URR8PPP <!-- main_leaderboard, all: [728,90][970,90][320,50][468,60] --> JavaScript Common Mistakes ❮ Previous Next ❯ This chapter points out some common JavaScript mistakes. Accidentally Using the Assignment Operator JavaScript programs may generate unexpected results if a programmer accidentally uses an assignment operator (=), instead of a comparison operator (==) in an if statement. This if statement returns false (as expected) because x is not equal to 10: var x = 0; if (x == 10) Try it Yourself » This if statement returns true (maybe not as expected), because 10 is true: var x = 0; if (x = 10) Try it Yourself » This if statement returns false (maybe not as expected), because 0 is false: var x = 0; if (x = 0) Try it Yourself » An assignment always returns the value of the assignment. Expecting Loose Comparison In regular comparison, data type does not matter. This if statement returns true: var x = 1...