函数
函数就是一段可以反复调用的代码块
//无参数类型
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);