Blogger Information
Blog 22
fans 0
comment 0
visits 11443
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
函数参数与返回值和模板字面量与模板函数
没耐心的渔翁
Original
445 people have browsed it

函数参数与返回值

实参和行参一样的

let fn= function(a,b){ return a + b ; } console.log(fn(1,2));

行参和实参不一样的 行参给个值

let fn= function(a,b=3){ return a + b ; } console.log(fn(1));

实参大于形参。可以用数组(…)

let fn =function(a,b){ return a+b; } console.log(fn(1,2,3,4,5)); //无法接受到全部的参数,这里我们需要用剩余参数’…‘ let fn =function(a,b,...c){ console.log(a,b,c) } fn(1,2,3,4,5); //把数组打散 let arr= [1,2,3,4,5]; console.log(...arr); console.log(fn(...arr));

函数返回值

返回多个值 对象 数组

` let ss = function(){ return [1,3,3,4,5,6,4,6,]} console.log(ss()); function sss(){ return{ id:1, name:'jack', email:'php@cc' } } console.log(sss());

模板字面量

反引号支持在字符串插入变量/表达式: 插值;

let name = `PHP中文网`; console.log(`hello ${name}`);
let xxx=1; console.log(`${xxx? `这是${name}` :`输入错误` }`);

模板函数

模板函数的参数

第一个参数:模板字面量中的””字符串字面量”(strings)
第二个参数:模板字面量中的””插值”数组(…args)
` calc`订单:${10}单价:${5}` function calc(strings,...args){ console.log(strings); console.log(args); console.log(args[0] * args[1]); }

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post