The quirks of JavaScript

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

* @authors Benjamin()
* @date 2013-11-29 14:04:00
* @Those quirks content summary JavaScript(trick)

* Trick01:NaN is the number ofvalue
* NaN: A number of value, value not; but it is the number of value, and is not equal to its own;

console.log(typeof NaN);//number
console.log(NaN == NaN);//false
console.log(NaN === NaN);//false

* Trick02:Null is an object
* One of the Null:javascript in the five basic types, it has a unique value null, namely literal it, defined as completely pointless value. Examples of null than any object:

console.log(typeof null);//Object
console.log(null instanceof Object);//false

* trick03:undefined
* Undefined:undefined and reserved words not in JavaScript, although it has a special significance, and is the only way to determine whether a variable is not defined, but it can be defined as variables

var Benjamin;
console.log(typeof Benjamin);//undefined
undefined = "My name is Benjamin";
console.log(undefined == Benjamin);//true

* The trick04: function can perform their own
* One case: jQuery code package
* Case two: application of delay function in the



var name = "Benjamin";
	return function(){
var name = "Benjamin01";

//2.1,This is also a beginner and interview often meet the problem
var name = "Benjamin";
var name = "Benjamin01";

* Trick05: implicit type conversion, such as like: {}+{} = ? or [] + [] = ?

console.log({} + {});//[object Object][object Object]
});//[object Object][object Object]
console.log([] + {}); //[object Object]
console.log({} + []); //[object Object]
console.log([] + []); //The empty string

When it comes to type conversion, below to have a look the most fundamental thing, type conversion in ECMASCRIPT 5.1 and test:

For details see Bowen: the type conversion in JavaScript

* Trick06: equal sign (=) and inequality(!=)

console.log(0   == false);//true
console.log(1   == true );//true
console.log(2   == true );//false
console.log("0" == false);//true
console.log("1" == true );//true
console.log("2" == true );//false
console.log(""  == 0    );//true
console.log(""  == false);//true
console.log("         " == 0    );  //true
console.log("         " == false);  //true
console.log("\n 123 \t" == 123  );  //true

* Trick07: does not use the VaR define the variable name will automatically create global variables

function Benjamin(){
	Ben = "Benjamin";

function Benjamin(){
	var Ben = "Benjamin";
console.log(Ben);//ReferenceError: Ben is not defined

* The scope of trick08: variables
Reference linking: process of JavaScript engine scripts
* The trick09: class array object
Array object:
1)A: index, the length property access
2)Do not have method such as: push, forEach and indexOf with the array object
3)The array object class common:
a)Some DOM methods, for example
b)Special variable arguments
4)Array object is converted to an array object

5)Methods the array object using the array object
fn: Methods the array object., indexOf,slice,concat,push,pop,etc., arg0, arg1, ...)

function Benjamin(){
	var args = arguments;
	console.log(,1));//[2, 3, 4, 5]
	console.log(args.slice(1));//TypeError: args.slice is not a function

Subsequent supplementation...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Ellis at December 01, 2013 - 10:47 PM