【发布时间】:2012-02-03 23:21:17
【问题描述】:
我在找出以下代码有什么问题时遇到了问题。我已经咨询过如何使用typeof 和switch cases,但我现在迷路了。提前感谢您的建议。
// Write a function that uses switch statements on the
// type of value. If it is a string, return 'str'. If it
// is a number, return 'num'. If it is an object, return
// 'obj'. If it is anything else, return 'other'.
function detectType(value) {
switch (typeof value) {
case string:
return "str";
case number:
return "num";
default:
return "other";
}
}
------------- 更新 --------------------------------- --
原来问题出在我没有正确遵循说明的错误(或者更确切地说是疏忽)。再次感谢您的帮助和 cmets!
【问题讨论】:
标签: javascript switch-statement typeof