1.实例代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>DEMO</title>
</head>
<body>
<script >
let number=12
console.log("number :",typeof number,number)
let name="devinwon"
console.log("name :",typeof name,name)
//定义后不能修改
const pi=3.1415926
console.log('pi',pi)
//pi=3.15
//布尔类型
isboy=true
console.log('isboy',isboy,typeof isboy)
// 对象,复合数据类型,存储多个键值对
let person={
name:"David",
address:"chnshenzhen",
}
console.log("person:",person,typeof person)
//map,存储键值对的有序集合
// let contact=new Map()定义了一个空的
let contact=new Map([
["name","kitty"],
["age",18],
])
console.log("contact:",contact,typeof contact)
// set
let st=new Set([1,2,3,4,5,5,43])
console.log("st",st,typeof st)
let arr=["a","b","c",120]
console.log("arr",arr,typeof arr)
//函数function
function add(x,y){
console.log(x+y)
}
// console.log("add(1,20)=",add(1,20))
add(21,23)
//匿名函数
let rel=function(x,y){
return x-y
}
console.log("调用匿名函数:",rel(100,98))
// 箭头函数,省略了关键字function
let plus=(a,b)=>{
return a*b
}
console.log("箭头函数:",plus(30,5))
// 隐式返回, 同箭头函数,更简洁
let plus2=(a,b)=>a*b
//class
class Person{
name
age
constructor(name,age){
this.name=name
this.age=age
}
info(){
console.log("name:",this.name)
console.log("age:",this.age)
}
}
// 类的实例化
let per=new Person("devin",19)
per.info()
</script>
</body>
</html>