function isNumber(val){
if((typeof(val)==‘number‘)||(val instanceof Number)){
return true
}else{
return false
}
}
function isString(val){
if((typeof(val)==‘string‘)||(val instanceof String)){
return true
}else{
return false
}
}
function isBoolean(val){
if((typeof(val)==‘boolean‘)||(val instanceof Boolean)){
return true
}else{
return false
}
}
function isArray(val){
if(val instanceof Array){
return true
}else{
return false
}
}
var a = new Number(1)
var b = new String(‘a‘)
var c = new Boolean(true)
var d = new Array(1,2,3)
var e = 1
var f = ‘f‘
var g = false
var h = [1,2,3]
function isNumber(val){
if((typeof(val)==‘number‘)||(val instanceof Number)){
return true
}else{
return false
}
}
function isString(val){
if((typeof(val)==‘string‘)||(val instanceof String)){
return true
}else{
return false
}
}
function isBoolean(val){
if((typeof(val)==‘boolean‘)||(val instanceof Boolean)){
return true
}else{
return false
}
}
function isArray(val){
if(val instanceof Array){
return true
}else{
return false
}
}
console.log(isNumber(a))
console.log(isString(b))
console.log(isBoolean(c))
console.log(isArray(d))
console.log(isNumber(e))
console.log(isString(f))
console.log(isBoolean(g))
console.log(isArray(h))
b. 输出:
true
true
true
true
true
true
true
true
原文地址:http://blog.51cto.com/12173069/2092266