js中在6版本前有6种(Number,null,Object ,String,undefined,boolean),在6之后是7种加了一个symbol
第一种:boolean型只有两个值 flase or ture
第二种:undefined (定义变量的默认初始值)
第三种:Number 数字
第四种: String类型
第五种:Null 类型
第六种:Object类
<!DOCTYPE html>
<html>
<head>
<title>javaScript中的数据类型</title>
</head>
<body>
<script type="text/javascript">
/*Object类型的数据 所有数据类型的超类 自定的类默认继承Object
Object 属性:prototype 给类动态的扩展属性和函数
constructor
函数:toString()
valueOf()
toLocalString()
js中定义类和创建对象
function 类名(形参){ }
类名=function(形参){ }
创建对象:
new 类名(实参)
function class(){
}
class();函数调用
new class();创建类的对象
*/
function student(){
alert("student........");
}
student();//函数调用
var str=new student();
alert(str);//[object Object]
function user(a,b,c){
this.sno=a;
this.sname=b;
this.sage=c;
this.tostring= function() {
return this.sno;
}
}
var u1=new user(111,"张三",20);
var useru1=u1.tostring();
alert(useru1);
//通过prototype动态扩展属性和函数
user.prototype.getsname=function()
{
return this.sname;
}
alert(u1.getsname());
</script>
</body>
</html>
其中重要的函数有 typeof()判断变量的数据类型,isNaN()确定不是数字,parseInt(),parseFloat(),Math.ceil()取整数!