Some typeof return values

Calling the typeof operator on a variable or value returns one of the following values:

  • undefined - if the variable is of type Undefined
  • boolean - if the variable is of type Boolean
  • number - if the variable is of type Number
  • string - if the variable is of type String
  • object - if the variable is a reference type or of type Null

Note: typeof(null) returns object;

Also: alert(null == undefined); // output "true"

The value undefined is actually derived from the value null, so ECMAScript defines them as equal.

Example: var exp = undefined;

    if (exp == null)

    {

        alert("is null"); // is null will pop up

    }

Then here’s another chestnut:

1、typeof([]); // "object"
2、typeof({}); //"object"

3、typeof([]) === typeof({}); // true

By the way:

1. {a:1}=={a:1} // false, reference types compare their addresses

 

Guess you like

Origin blog.csdn.net/khadijiah/article/details/102765762