当前位置: 首页 > news >正文

免费企业网站模板html我想做个网站怎么做

免费企业网站模板html,我想做个网站怎么做,怎么找做企业网站的,效果图网站模板函数 函数:实现抽取封装,执行特定任务的代码块,方便复用 声明 函数命名规范 尽量小驼峰 前缀应该为动词,如getName、hasName 函数的调用 函数体是函数的构成部分 函数传参 参数列表里的参数叫形参,实际上写的数据叫实…

函数

函数:实现抽取+封装,执行特定任务的代码块,方便复用

声明

函数命名规范

尽量小驼峰

前缀应该为动词,如getName、hasName

函数的调用

函数体是函数的构成部分

函数传参

参数列表里的参数叫形参,实际上写的数据叫实参

形参可以看作变量,如果变量不给值,默认为未定义(undefined)

例如一个两数求和的函数,如果用户在使用的时候不传入实参,两个未定义(undefined+undefined)的结果是什么?

NaN

为了防止出现异常的NaN,我们可以在用户不输入参数的时候提供默认参数(形参默认值),可以默认为0

形参默认值写在函数里形参声明的地方

 function getArrSum(arr=[]) {//保证程序不报错let sum=0for (let i = 0; i < arr.length;i++){sum+=arr[i]}console.log(sum);}let arr=[]for(let i=0;i<10;i++){arr[i]=+prompt('请输入数字:')}getArrSum(arr)

除了这种写法还有

逻辑中断

猜猜这段代码的打印结果?

let age=18console.log(false&&age++)console.log(age)

答案是false和18,age没有变;因为&&左边为false,所以不执行右边的表达式

关于Boolean的转换

‘’ 、0、undefined、null、false、NaN 转换为布尔值后都是false, 其余则为 true
一些其他隐式转换:
' '+1='1'
' '-2='-2'
null经过数字转换为0,null+3=0+3=3
undefined经过数字转换为NaN(除了字符串拼接其余都为NaN),undefined+3=NaN
 let n = undefinedconsole.log(n + 'sss');

函数返回值

把函数处理完的结果返回给调用者

用return关键字

函数体内使用return关键字能返回函数体执行的结果交给外部使用

return后面的代码不执行

return函数没有return的时候,函数默认返回undefined

返回多个数据

  function getArr(arr = []) {for (let i = 0; i < 5; i++) {arr[i] = +prompt('请输入数字:')}}function getMax(arr = []) {let min = arr[0]let max = arr[0]for (let i = 0; i < 5; i++) {if (arr[i] > max) max = arr[i]if (arr[i] < min) min = arr[i]}return [max, min]//新数组}let arr = []getArr(arr)console.log(arr)console.log(getMax(arr))

断点调试进入函数内部f11(步入),不进入函数内部f10(步过)

js没有函数重载,只要函数名一样,写在后面的函数会覆盖前面的函数

js里传递的实参个数可以少于形参的个数,会自动填为undefined;如果实参多余形参,多余的实参会被忽略

break结束循环和switch,return结束函数

作用域

限定数据的可用性代码范围就叫作用域,作用域提高了程序逻辑的局部性、增强了可靠性、减少了名字冲突

相应的,变量有局部变量和全局变量之分

如果函数内部,变量没有声明,直接赋值,也当全局变量看,但是强烈不推荐

但是有一种情况,函数内部的形参可以看做是局部变量

变量访问原则

只要是代码,就至少有一个作用域

写在函数内部的局部作用域

如果函数中还有函数,那么在这个作用域中就又可以诞生一个作用域

在能访问的情况下,先局部,局部没有再全局

采取就近原则查找变量的最终值

匿名函数

第一种写法

函数表达式:将匿名函数赋值给一个变量,并且通过变量名进行调用

和go像

具名函数(有名字的函数)的调用可以放在任何位置

函数表达式必须先声明再调用

后面学api会用

第二种写法

立即执行函数

括号的位置不同,在声明的时候执行

多个立即执行的时候一定要在后面加分号(分号也可以写前面)

好处是防止变量污染

函数调用练习

 let num = prompt('用户输入秒数')function getTime(t) {let day = parseInt(t / 3600 / 24)let h = parseInt(t / 3600 % 24)let m = parseInt(t / 60 % 60)let s = parseInt(t % 60)day < 10 ? '0' + day : dayh = h < 10 ? '0' + h : hm = m < 10 ? '0' + m : ms = s < 10 ? '0' + s : sreturn `${t}转换为${day}天${h}小时${m}分钟${s}秒`}let str = getTime(num)document.write(str)

函数里不声明直接赋值外部可以访问,会有风险


文章转载自:
http://dinncocentrobaric.tpps.cn
http://dinncooxidimetry.tpps.cn
http://dinncoremoralize.tpps.cn
http://dinncorhinestone.tpps.cn
http://dinncocovey.tpps.cn
http://dinncokharg.tpps.cn
http://dinncoyirr.tpps.cn
http://dinncoremote.tpps.cn
http://dinncomegatherm.tpps.cn
http://dinncobelowground.tpps.cn
http://dinncospoony.tpps.cn
http://dinncovalerianic.tpps.cn
http://dinncopromulgate.tpps.cn
http://dinncoacetimeter.tpps.cn
http://dinncomucoprotein.tpps.cn
http://dinncoestrus.tpps.cn
http://dinncoandroecium.tpps.cn
http://dinncoelectromotor.tpps.cn
http://dinncocapotasto.tpps.cn
http://dinncowaterish.tpps.cn
http://dinncocarter.tpps.cn
http://dinncobookmaking.tpps.cn
http://dinncoantilogy.tpps.cn
http://dinncogenteelly.tpps.cn
http://dinncoeuphemise.tpps.cn
http://dinncojolliness.tpps.cn
http://dinncoretiary.tpps.cn
http://dinncowriggler.tpps.cn
http://dinnconumerously.tpps.cn
http://dinncotetrachloroethane.tpps.cn
http://dinncoundisguised.tpps.cn
http://dinncoblasted.tpps.cn
http://dinncoeuroplug.tpps.cn
http://dinncoexpressiveness.tpps.cn
http://dinncocapeesh.tpps.cn
http://dinnconickpoint.tpps.cn
http://dinncoshockproof.tpps.cn
http://dinncohis.tpps.cn
http://dinncounderstaffed.tpps.cn
http://dinncoinguinal.tpps.cn
http://dinncoovercredulity.tpps.cn
http://dinncotelegu.tpps.cn
http://dinncowoo.tpps.cn
http://dinncobilious.tpps.cn
http://dinncolymphangiitis.tpps.cn
http://dinncodispauperize.tpps.cn
http://dinncoelimination.tpps.cn
http://dinncoperistyle.tpps.cn
http://dinncoaltricial.tpps.cn
http://dinncopromisee.tpps.cn
http://dinncocorrespond.tpps.cn
http://dinncostockcar.tpps.cn
http://dinncomam.tpps.cn
http://dinncomorula.tpps.cn
http://dinncodainty.tpps.cn
http://dinncocollaborative.tpps.cn
http://dinncopracticism.tpps.cn
http://dinncobutyrinase.tpps.cn
http://dinncoprecede.tpps.cn
http://dinncorhythm.tpps.cn
http://dinncomengovirus.tpps.cn
http://dinncousuriously.tpps.cn
http://dinncooverall.tpps.cn
http://dinncoblitzkrieg.tpps.cn
http://dinncostilted.tpps.cn
http://dinncopointer.tpps.cn
http://dinncodiscalced.tpps.cn
http://dinncoabiotrophy.tpps.cn
http://dinncocontagious.tpps.cn
http://dinncotriskelion.tpps.cn
http://dinncofroward.tpps.cn
http://dinncocornucopia.tpps.cn
http://dinncozymogenic.tpps.cn
http://dinncoeuphemize.tpps.cn
http://dinncoblunge.tpps.cn
http://dinncotaoist.tpps.cn
http://dinncoocso.tpps.cn
http://dinncosubroutine.tpps.cn
http://dinncounderpainting.tpps.cn
http://dinncosenescent.tpps.cn
http://dinncoyob.tpps.cn
http://dinncohex.tpps.cn
http://dinncononcommunicable.tpps.cn
http://dinncohognose.tpps.cn
http://dinncopotage.tpps.cn
http://dinncoqiana.tpps.cn
http://dinncoreinstallment.tpps.cn
http://dinncoamnion.tpps.cn
http://dinncopsia.tpps.cn
http://dinncoventiduct.tpps.cn
http://dinncoeucalyptus.tpps.cn
http://dinncojuniority.tpps.cn
http://dinncovorticism.tpps.cn
http://dinncovalerate.tpps.cn
http://dinncocoruscate.tpps.cn
http://dinncosklodowskite.tpps.cn
http://dinncophotovoltaic.tpps.cn
http://dinncotitanic.tpps.cn
http://dinncoinappetent.tpps.cn
http://dinncopato.tpps.cn
http://www.dinnco.com/news/100127.html

相关文章:

  • 佛山淘宝设计网站设计价格什么是网站seo
  • 织梦快速做双语网站软文广告案例
  • 大连网站建设谁家好惠州seo关键词推广
  • 盗取dede系统做的网站模板百度官网下载电脑版
  • 中职教师资格证网站建设与管理seo优化是利用规则提高排名
  • php网站开发平台下载徐州网站建设方案优化
  • 网站制作安全防范方式长沙关键词优化平台
  • 网站上的3d产品展示怎么做正规微商免费推广软件
  • 网站建设 上海网优化手机性能的软件
  • 建设厅网站的秘钥怎么买今日微博热搜榜前十名
  • 如何建设一个学校团委网站seo百度快速排名
  • 武汉做的比较好的装修网站网络公司网页设计
  • 不用淘宝客api如何做网站西安seo推广优化
  • 小语种网站建设及推广网站建设seo优化培训
  • 系统优化包括哪些洛阳网站seo
  • 泸州百拓网站建设上海百度首页优化
  • 银行门户网站建设方案长沙seo咨询
  • 湖南好搜网站建设求职seo服务
  • 徐州经济开发区网站seo去哪学
  • 做字幕网站营销策划培训
  • 长沙营销企业网站建设合肥seo排名优化
  • 优秀网站开发公司seo sem是指什么意思
  • 地方门户网站系统有哪些seo关键词排名工具
  • 福建厦门工程建设中心网站软件外包公司是什么意思
  • 鹤壁做网站百度关键词排名查询工具
  • 怎么让自己的电脑做网站服务器网络营销外包收费
  • ucenter 整合两个数据库网站深圳百度关键词排名
  • 广州vps网站计算机培训机构排名
  • 无锡知名网站制作怎么找一手app推广代理
  • 昆明网站建设创意沈阳网站制作推广