
typeof 123 // 返回 "number"
typeof "Hello World" // 返回 "string"
typeof true // 返回 "boolean"
typeof undefined // 返回 "undefined"
typeof null // 返回 "object"
typeof [1, 2, 3] // 返回 "object"
typeof {"name": "小米", "age": 32} // 返回 "object"
typeof function() {} // 返回 "function"Object.prototype.toString.call(123) // 返回 "[object Number]"
Object.prototype.toString.call("Hello World") // 返回 "[object String]"
Object.prototype.toString.call(true) // 返回 "[object Boolean]"
Object.prototype.toString.call(undefined) // 返回 "[object Undefined]"
Object.prototype.toString.call(null) // 返回 "[object Null]"
Object.prototype.toString.call([1, 2, 3]) // 返回 "[object Array]"
Object.prototype.toString.call({"name": "小米", "age": 32}) // 返回 "[object Object]"
Object.prototype.toString.call(function() {}) // 返回 "[object Function]"
var arr = [1, 2, 3];
console.log(arr instanceof Array); // 返回 true
var obj = {"name": "小米", "age": 22};
console.log(obj instanceof Object); // 返回 true
function Person(name, age) {
this.name = name;
this.age = age;
}
var alex = new Person("小米", 32);
console.log(alex instanceof Person); // 返回 true
var arr = [1, 2, 3];
console.log(arr.constructor === Array); // 返回 true
var obj = {"name": "小米", "age": 18};
console.log(obj.constructor === Object); // 返回 true
function Person(name, age) {
this.name = name;
this.age = age;
}
var alex = new Person("小米", 18);
console.log(alex.constructor === Person); // 返回 true
JavaScript获取指定网站状态码查询代码(2种实现方法)
标签: constructor方法, instanceof方法, Object.prototype.toString方法, typeof方法
上面是“如何利用js语法判断数据类型”的全面内容,想了解更多关于 js 内容,请继续关注web建站教程。
当前网址:https://m.ipkd.cn/webs_4791.html
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

为什么有的企业喜欢更换域名?
豚豚剧 2025官网正版