(Effective JavaScript 68 Specific Ways to Harness the Power of JavaScript by David Herman - 2013, page 19) Java Beach Café

(Effective JavaScript 68 Specific Ways to Harness the Power of JavaScript by David Herman - 2013, page 26) For this approach to work, however, the contents of files cannot assume that they are interpreted at global scope. Do scope của var không thể outside function, mà chúng ta đang sử dụng chúng để handle việc strict mode

  • Decide which version of Javascript your application supports.
  • Be sure that any Javascript features you use are supported by all environments where your application runs.
  • Always test strict code in env that perform the strict-mode check
  • Beware of concatenating scripts that differ in their expectations about strict mode.

(Effective JavaScript 68 Specific Ways to Harness the Power of JavaScript by David Herman - 2013, page 28) Most programming languages have several types of numeric data, but JavaScript gets away with just one

(Effective JavaScript 68 Specific Ways to Harness the Power of JavaScript by David Herman - 2013, page 28) This simple-looking expression actually requires several steps to evaluate. As always, the JavaScript numbers 8 and 1 are doubles. But they can also be represented as 32-bit integers, that is, sequences of thirty-two 1’s and 0’s. As a 32-bit integer, the number 8 looks like this: 00000000000000000000000000001000 You can see this for yourself by using the toString method of numbers: (8).toString(2); // "1000"

(Effective JavaScript 68 Specific Ways to Harness the Power of JavaScript by David Herman - 2013, page 30) One useful workaround is to work with integer values wherever possible, since they can be represented without rounding.

Ex:

// floating-point
0.1 + 0.2 + 0.3 // 0.6000000000000001
0.1 + (0.2 + 0.3) // 0.6
 
// to handler money
10 + 20 + 30 // 60
10 + (20 + 30) // 60

(Effective JavaScript 68 Specific Ways to Harness the Power of JavaScript by David Herman - 2013, page 34) Since numbers and strings can be falsy, it’s not always safe to use truthiness to check whether a function argument or object property is defined

(Effective JavaScript 68 Specific Ways to Harness the Power of JavaScript by David Herman - 2013, page 36) This is an important difference, because it means that you can’t compare the contents of two distinct String objects using built-in operators:

var s1 = new String("hello")
var s2 = new String("hello")
s1 === s2 // false

(Effective JavaScript 68 Specific Ways to Harness the Power of JavaScript by David Herman - 2013, page 37) Object wrappers for primitive types do not have the same behavior as their primitive values when compared for equality.