Js的数据类型整理

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()取整数!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值