批改状态:合格
老师批语:

<!DOCTYPE html><html lang="zh-CN"><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>JS声明、初始化、作用域等演示 </title></head><body><!-- 引用外部JS脚本 --><!-- <script src="xxx.js"></script> --><!-- js内部脚本 --><script>// 声明变量 a,且初始化赋值let a =100;let b =50;// 查看结果// console:控制台对象console.log(a);console.log(b);// 匿名函数{a + b ;c = a + b ;console.log(c);console.log( a + b );let d = '早晨你好!' ;console.log(d);}// 命名函数 在js中, 字符串的拼装: "+",二边至少有一个字符串function sum ( a , b ){return a + b ;}console.log(sum('2022年' , ',早晨你好!' ));console.log(sum(10, 5 ));function sum ( f , g ) {let e = f + g ;return e ;}console.log(sum (50, 20));// 全局作用域 , 代码块/函数的外部声明的let email = 'abde@sina.com';{console.log(email);}let email2 = 'obq@sina.com' ;{let email2 = 'cdae@sina.com';console.log(email2);}console.log(email2);// 我是常量const H = 55 ;console.log(H);// 标识符可用的字符:// 1. 字母, 数字, 下划线, $// 2. 不能以数字开始let $abc = 22;console.log($abc);let _ab = '下划线';console.log(_ab);// 常量遵守标识符的规则,但是为了更快的识别它// 1. 全部使用大写字母// 2. 多个单词之间用下划线: USER_EMAIL// 变量的命名规则// (1). 驼峰式: username->// 1.1 小驼峰: username -> userName// 1.2 大驼峰: username -> UserName// 小驼峰: 变量,函数(动词+名词: getUserInfo())// 大驼峰: 类,构造函数, 还有一个别名: 帕斯卡命名法// (2) 蛇形命名法// 1. username -> user_name// 2. 常量: USER_NAME// 命名函数function getName(userName){return '在' +userName ;}console.log( getName('2022早晨'));// 匿名函数let getName1 = function (userName1){return '2022' + userName1 ;}console.log(getName1('年7月'));// 阅读及焚console.log((function (d_username) {return '今天是, ' + d_username;})('你的生日吗?')) ;// 简化匿名函数// 去掉 function 及形参的括弧,在形参的右侧增加 => 胖箭头getName1 = userName1 => {return 'hello,' + userName1 ;}console.log(getName1('地冬老师'));// 再次简化 ,去掉{ } ,去掉return 注意又有分号getName1 = userName1 =>'hello,' + userName1 ;console.log(getName1('猫老师'));let f = x => x * 5 ;console.log( f ( 10 ));f =(x ,z) => 5 * 5 ;console.log( f() );f =( x ,z ) => x + z ;console.log(f( 8 , 9 ));f =() => '今天是个好日子。'console.log(f());</script></body></html>
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号