常量、变量与函数
作业标题:0707作业
作业内容:
- 变量,常量,数据类型,实例演示,注意命名规范;
- 函数参数与返回值,匿名函数及箭头函数的转化,实例演示;
变量,常量,数据类型,实例演示
- 代码
<!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>常量与变量</title>
</head>
<body>
<!-- 常量 -->
<script>
const TEST = "abcd";
console.log(TEST);
// 变量
let userName = "张老师";
console.log(userName);
//基本数据类型 数值型
let name = 10;
console.log(typeof name);
//字符型
userName = "张老师";
console.log(typeof userName);
//布尔型
let test = true;
console.log(typeof test);
//undefined型
let test1;
console.log(typeof test1);
//null型
let test2 = null;
console.log(typeof test2);
//引入型数据类型
//数组
const test3 = [1, 2, 3, 4, 5];
console.log(typeof test3);
//对象
const test4 = { id: 002, userName: "张三" };
console.log(typeof test4);
//函数
function test5() {
return console("aaa");
}
console.log(typeof test5);
</script>
</body>
</html>
函数参数与返回值,匿名函数及箭头函数的转化
代码
<!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>函数参数与返回值,匿名函数及箭头函数的转化,实例演示</title>
</head>
<body>
<script>
// 函数参数与返回值
function student(a, b) {
return a + b;
}
console.log(student(40, 50));
// 匿名函数
let sum = function (a, b) {
return a + b;
};
console.log(sum(30, 50));
//箭头函数
let sum1 = (a, b) => a + b;
console.log(sum1(10, 60));
</script>
</body>
</html>