JS函数 对象 Math Date

函数

函数就是一段可以反复调用的代码块

		//无参数类型
		function add(){
			console.log("666666")
		}
		//调用
		add();
		
		
		//有参数类型
		function add(x,y){
            console.log(x + y);
        }
        add(20, 30);

		//返回值类型
		function add(x, y) {
            return x + y;
        }
        
        var result = add(20, 30);
        console.log(result);

对象

对象里面可以有很多种类型,甚至可以是对象

		// 创建一个对象
        var user = {
            name:"whx",
            age:18,
            right:true,
            hobby:["play", "work", "study"],
            eat:function(){
                console.log("eat something");
            }
        }
		// 对象的调用
        user.name;
        user.age;

Math对象

Math.abs()

返回参数值的绝对值

Math.max()和Math.min()

最大值,最小值
如果参数为空,min方法会返回infinity、max方法会返回-infinity

Math.floor()和Math.ceil()

最近的一个整数

Math.random()

返回0~1之间的一个伪随机数,能等于0,一定小于1

Date对象

以1970年1月1日00:00:00为时间零点

Date.now()

返回当前时间距离时间零点的毫秒数

get方法

getTime()获取一个毫秒数,时间戳
getDate()返回实例对象对应的几号
getDay()返回星期几,0为星期日,1为星期一
getYear()返回距离1900的年数
getFullYear()返回四位数的年份
getMonth()获取月份,0代表一月,11代表12月
getHours()返回小时
getMilliseconds()毫秒
getMinutes()分钟
getSeconds()秒

		//获取年月日
		var year = new Date().getFullYear();
        var month = new Date().getMonth();
        var date = new Date().getDate();

        console.log(year + "-" + (month+1) + "-" + date);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值