Skip to content

Instantly share code, notes, and snippets.

@leohxj
Created May 28, 2014 02:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leohxj/7bea17e408c4178ed82d to your computer and use it in GitHub Desktop.
Save leohxj/7bea17e408c4178ed82d to your computer and use it in GitHub Desktop.
typeof运算符和Object.prototype.toString
typeof {foo: 'bar'};
// "object"
typeof ['foo', 'bar'];
// "object"
typeof "foobar";
// "string"
typeof /foo|bar/;
// "object"
Object.prototype.toString.call({foo: 'bar'});
// "[object Object]"
Object.prototype.toString.call(['foo', 'bar']);
// "[object Array]"
Object.prototype.toString.call("foobar");
// "[object String]"
Object.prototype.toString.call(/foo|bar/);
// "[object RegExp]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment