码迷,mamicode.com
首页 > Web开发 > 详细

js学习记录

时间:2017-08-30 11:56:35      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:null   object   对象   cto   float   rip   记录   script   eof   

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学习记录

标签:null   object   对象   cto   float   rip   记录   script   eof   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!