初探javaScript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// 变量 命名规则,遵循驼峰式,或蛇形式
let num = 12; //值类型
// 常量 一般字母全大写
const P = 3.14;
// 数据类型
let str = "Hello"; //字符串
let bool = true; //布尔 (以及Null,Undefined类型)
function printStr(){
console.log("值类型变量num:"+num+"常量P:"+P+"字符串类型str:"+str+"布尔类型bool:"+bool);
}
// 匿名函数
let func = function (){
console.log("值类型变量num:"+num+"常量P:"+P+"字符串类型str:"+str+"布尔类型bool:"+bool);
}
// 箭头函数转化
let funct = () => console.log("值类型变量num:"+num+"常量P:"+P+"字符串类型str:"+str+"布尔类型bool:"+bool);
function returnData(){
return '返回值';
}
function returnData(...arr){
let num = 0;
for(let i = 0; i < arr.length; i ++){
num += arr[i];
}
return num;
}
func();
funct();
returnData();
let arr = [1,2,3,4,5,6]
console.log(returnData(...arr)) //归并,若参数为数组,必须加...,否则无法展开
</script>
</body>
</html>