javacript基本语法

javacript基本语法

演示变量,常量,与常用的四种函数类型

变量,常量//变量推荐用let声明,常量用const声明let username =张三;console.log(username)// 变量值可以被更新、修改username =李四;console.log(username);// 常量// 创建常量时,必须初始化const gender =console.log(gender)//常量被声明后不能修改错误做法:const gender =gender =“女”函数类型//命名函数function f(a,b){return`${a} * ${b} = ${a*b}`;}console.log搭建项目系统点我wcqh.cn(f(2,3))// 匿名函数let f2 =function(a,b){return`${a} * ${b} = ${a*b}`;}console.log(f2(3,4))// 箭头函数,匿名函数的简化// let 禁止重复声明,var可以// 1. 删除关键字 function// 2. 在(参数列表)与{代码块}之间用”胖箭头”(=>)let f3 =(a,b)=>{return`${a} * ${b} = ${a*b}`;}console.log(f3(4,5))// 当参数不足时,使用默认参数 f3 =(a,b=1)=>{return`${a} * ${b} = ${a*b}`;}console搭建项目系统点我wcqh.cn.log(f3(6))//当函数参数只有一个时,括号可以不写f3 = uname =>{return`hello ${uname}`;}console.log(f3(青狐资源网))//没有参数时 括号不能省略f3 =()=>{return“hello world!”}console.log(f3())//函数体只有return一行代码 可以不写return ,大括号也要省略f3 =(a,b)=> a*b;console.log(f3(7,8));//立即执行函数 IIFE//将声明和调用二合一,声明完成直接运行,将函数使用括号包起来使函数运行(function f4(a,b){ console.log(`$搭建项目系统点我wcqh.cn{a} * ${b} = ${a*b}`)})(9,10);(function(a,b){ console.log(`${a} * ${b} = ${a*b}`)})(11,12);((a,b)=>{ console.log(`${a} * ${b} = ${a*b}`)})(13,14);((a,b)=> console.log(`${a} * ${b} = ${a*b}`))(15,16);

实例演示五种基本数据类型

// 数值型//不区分整数和小数,numberconsole.log(123,typeof123)//字符串 (xxx,”xxx”,`xxx`) stringconsole.log(搭建项目系统点我wcqh.cnhi”,typeof“hi”)console.log(hello world)console.log(“hello world”)console.log(`hello world`)//布尔类型 true or false booleanconsole.log(true,typeoftrue)//null,空对象console.log(null,typeofnull)//undefined, 未定义console.log(email)
批改老师:PHPz 批改状态:合格 老师批语:
作者最新博文
2023-01-15 19:11:09

© 版权声明
THE END
喜欢就支持一下吧
点赞794 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容