分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 前端开发

js学习记录

发布时间:2023-09-06 01:07责任编辑:傅花花关键词:js

js  数据类型

typeof "John"                 // 返回 string
typeof 3.14                   // 返回 number
typeof NaN                    // 返回 number                 isNaN(),判断是否为非数值
typeof false                  // 返回 boolean
typeof [1,2,3,4]              // 返回 object                    数组比较特殊,返回object类型
typeof {name:‘John‘, age:34} // 返回 object
typeof new Date()             // 返回 object
typeof function () {}         // 返回 function
typeof myCar                  // 返回 undefined (如果 myCar 没有声明)
typeof null                   // 返回 object              
undefined                      //undefined
 
constructor 属性返回所有 JavaScript 变量的构造函数。你可以使用 constructor 属性来查看对象是否为数组 (包含字符串 "Array"):
 
 
"John".constructor                 // 返回函数 String()  { [native code] }
(3.14).constructor                 // 返回函数 Number()  { [native code] }
false.constructor                 // 返回函数 Boolean() { [native code] }
[1,2,3,4].constructor             // 返回函数 Array()   { [native code] }
{name:‘John‘, age:34}.constructor // 返回函数 Object()  { [native code] }
new Date().constructor            // 返回函数 Date()    { [native code] }
function () {}.constructor        // 返回函数 Function(){ [native code] }
 
 
 
 
 
类型转换,
数组转换为数字。
Number("3.14")    // 返回 3.14
Number(" ")       // 返回 0
Number("")        // 返回 0
Number("99 88")   // 返回 NaN
 
转换为字符串
String(),    X.toString().
字符串转换为整数,parseInt("A")          parseFloat()
 
 
 

js学习记录

原文地址:http://www.cnblogs.com/zl0717/p/7452094.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved