且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

JavaScript typeof运算符是否返回大写字符串?

更新时间:2022-11-09 08:22:19

Spidermonkey似乎只返回这些:

Spidermonkey seems to return only these:

"undefined"
"object"
"function"
"string"
"number"
"boolean"
NULL

https://developer.mozilla.org/ en / SpiderMonkey / JSAPI_Reference / JS_GetTypeName

与V8相同:

default:
  // For any kind of object not handled above, the spec rule for
  // host objects gives that it is okay to return "object"
  return isolate->heap()->object_symbol();

http://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/runtime.cc#5245

不知道MS,我猜他们也不使用自定义类型,但你永远不会知道它们。

No idea about MS, I guess they don't use custom typeof either, but you never know with them.


typeof返回有六个可能的值:number,string,boolean,object,function和undefined。

There are six possible values that typeof returns: "number," "string," "boolean," "object," "function," and "undefined."

http://msdn.microsoft.com/en-us/library/windows/apps/259s7zc1%28v=vs.94%29.aspx