获取参数对应的事件对象 | let date=new Date() | ||||||||||||||||||||
年 | let year=date.getFullyear() | ||||||||||||||||||||
月 | let mon=date.getMonth() | ||||||||||||||||||||
日 | let day=date.getDat()
| ||||||||||||||||||||
时 | let hour=date.getHours() | ||||||||||||||||||||
分 | let mm=date.getMinytes() | ||||||||||||||||||||
秒 | let ss=date.getSeconds() | ||||||||||||||||||||
星期几 | let week=date.getDay() | ||||||||||||||||||||
毫秒数 | let ms=date.getMilliseconds() | ||||||||||||||||||||
获取时间数 | let ts=date.getTime()
|
使用string() | let str1=new string() |
3/ | lwt str2=steing() |
和+的作用类似 | let str3=str1.concat(str2) |
链接字符串 | let str1="nanjing" let str2="jincheng1234" |
getSum(123) | |
函数 | 一段独立功能的代码集合 |
function函数名(参数) | {代码} |
let a = getSum(4, 5)
console.log(a)
function getSum(num1, num2) {
// console.log(num1 + num2)
return num1 + num2
console.log("66666你老6")
}
一个函数没有return的情况下,默认返回的是undefined
let sum=getSum(3,4)
引用传递 | let arr=[1,2,3] |
function change(a) {
// a += 10
// b += 20
a.push(100)
}
// change(a, b)
// console.log(a)
// console.log(b)
change(arr)
console.log(arr)
全局作用域,函数作用域
let a = 1
function fn() {
let num = 1
console.log(a)
}
fn()
console.log(num)
函数作为参数进行传递
function fn1() {
console.log("")
}
function fn2(a) {
a()
console.log("")
}
fn2(fn1)
箭头函数
// function fn(x) {
// return x + 5
// }
// let a = fn(4)
// console.log(a)
// let fn = () => alert("hello")
let fn = x => x + 5
console.log(fn(4))
let fn1 = (x, y) => {
let f = 6
return x + y + z
}