JS - wild-blooming/jot-down GitHub Wiki
Why closure/nested functions
make global var private with closure. reach nested function from outside???
The strict equality operator ===
evaluates its operands, and then compares the two values as follows, performing no type conversion: • If the two values have different types, they are not equal. • If both values are null or both values are undefined, they are equal. • If both values are the boolean value true or both are the boolean value false, they are equal. • If one or both values is NaN, they are not equal. The NaN value is never equal to any other value, including itself! To check whether a value x is NaN, use x !== x. NaN is the only value of x for which this expression will be true. • If both values are numbers and have the same value, they are equal. If one value is 0 and the other is -0, they are also equal. • If both values are strings and contain exactly the same 16-bit values (see the sidebar in §3.2) in the same positions, they are equal. If the strings differ in length or content, they are not equal. Two strings may have the same meaning and the same visual appearance, but still be encoded using different sequences of 16-bit values. JavaScript performs no Unicode normalization, and a pair of strings like this are not considered equal to the === or to the == operators. See String.localeCompare() in Part III for another way to compare strings. • If both values refer to the same object, array, or function, they are equal. If they refer to different objects they are not equal, even if both objects have identical properties.
The equality operator ==
is like the strict equality operator, but it is less strict. If the values of the two operands are not the same type, it attempts some type conversions and tries the comparison again: • If the two values have the same type, test them for strict equality as described above. If they are strictly equal, they are equal. If they are not strictly equal, they are not equal. • If the two values do not have the same type, the == operator may still consider them equal. Use the following rules and type conversions to check for equality: — If one value is null and the other is undefined, they are equal. — If one value is a number and the other is a string, convert the string to a number and try the comparison again, using the converted value. — If either value is true, convert it to 1 and try the comparison again. If either value is false, convert it to 0 and try the comparison again. — If one value is an object and the other is a number or string, convert the object to a primitive using the algorithm described in §3.8.3 and try the comparison again. An object is converted to a primitive value by either its toString() method or its valueOf() method. The built-in classes of core JavaScript attempt valueOf() conversion before toString() conversion, except for the Date class, which performs toString() conversion. Objects that are not part of core Java- Script may convert themselves to primitive values in an implementation-defined way. — Any other combinations of values are not equal.