* *** @ AuthorsBenjamin (http: blogcsdnnetcuew1987) * @ date2013-11-2914: 04: 00 * @ content summarizes the quirks of javascript (trick) *** trick01: naN is the number & amp; 2054
/**
*
* @ Authors Benjamin (http://blog.csdn.net/cuew1987)
* @ Date 2013-11-29 14:04:00
* @ Content summarize the quirks of javascript (trick)
*/
/**
* Trick01: NaN is a numerical value.
* NaN: indicates that a value is not a numerical value, but is a numerical value and is not equal to its own value.
*/
console.log(typeof NaN);//numberconsole.log(NaN == NaN);//falseconsole.log(NaN === NaN);//false
/**
* Trick02: Null is an object.
* Null: one of the five basic types in javascript. It has a unique null value, that is, its literal value, which is defined as a value that has no meaning at all. Null is not an instance of any object:
*/
console.log(typeof null);//Objectconsole.log(null instanceof Object);//false
/**
* Trick03: undefined
* Undefined: undefined is not a reserved word in JavaScript. Although it has a special meaning and is the only way to determine whether a variable is undefined, it can be defined as a variable.
*/
var Benjamin;console.log(typeof Benjamin);//undefinedundefined = "My name is Benjamin";console.log(undefined == Benjamin);//true
/**
* Trick04: the function can execute itself.
* Case 1: jQuery code Encapsulation
* Case 2: Applications in latency Functions
*/
// 1.0 (function ($) {}) (jQuery); // 2.0var name = "Benjamin"; setTimeout (function (name) {return function () {console. log (name); // Benjamin }}) (name), 1000); var name = "Benjamin01"; // 2.1, this is also a common problem for beginners and interviews. var name = "Benjamin"; setTimeout (function () {console. log (name); // Benjamin01}, 1000); var name = "Benjamin01 ";
/**
* Trick05: Implicit conversions, such as: {}+ {}=? Or [] + [] =?
*/
Console. log ({}+ {}); // [object Object] [object Object] console. log ({"name": "Benjamin" }+ {"age": 20}); // [object Object] [object Object] console. log ([] + {}); // [object Object] console. log ({} + []); // [object Object] console. log ([] + []); // empty string
When it comes to type conversion, let's take a look at the most fundamental stuff, the type conversion and testing in ECMASCRIPT 5.1:
For details, refer to the blog post: conversions of types in javascript.
/**
* Trick06: equal sign (=) and not equal sign (! =)
*/
console.log(0 == false);//trueconsole.log(1 == true );//trueconsole.log(2 == true );//falseconsole.log("0" == false);//trueconsole.log("1" == true );//trueconsole.log("2" == true );//falseconsole.log("" == 0 );//trueconsole.log("" == false);//trueconsole.log(" " == 0 ); //trueconsole.log(" " == false); //trueconsole.log("\n 123 \t" == 123 ); //true
/**
* Trick07: a variable name that is not defined by var will automatically create a complete set of variables.
*/
function Benjamin(){Ben = "Benjamin";}Benjamin();console.log(Ben);//"Benjamin"function Benjamin(){var Ben = "Benjamin";}Benjamin();console.log(Ben);//ReferenceError: Ben is not defined
/**
* Trick08: Scope of the Variable
*/
Reference link: Process of processing scripts by the javascript Engine
/**
* Trick09: Class array object
*/
Class array object:
1) has: subscript index access, length attribute
2) not available: methods available for array objects such as push, forEach, and indexOf
3) Common class array objects:
A) some DOM methods, such
Document. getElementsByClassName ()
Document. getElementsByName ()
Document. getElementsByTagName ()
B) Special Variable arguments
4) convert a class array object to an array object
5) the method for class array objects to borrow array objects
Fn: Methods in the array object, indexOf, slice, concat, push, pop, etc.
Array. prototype. fn. call (arguments, arg0, arg1 ,...)
6) instance:
function Benjamin(){var args = arguments;console.log(args[0]);//1console.log(args.length);//5console.log(Array.prototype.slice.call(args,1));//[2, 3, 4, 5]console.log(args.slice(1));//TypeError: args.slice is not a function}Benjamin(1,2,3,4,5);
Supplement later...