Blogger Information
Blog 62
fans 3
comment 1
visits 29712
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js函数类型
kiraseo_wwwkiraercom
Original
336 people have browsed it

函数参数类型与返回值方法

  1. console.log("函数参数类型与返回值方法");
  2. let sum = function ( a , b){
  3. return a + b;
  4. };
  5. console.log("参数类型为number类型");
  6. console.log(sum(20,50));
  7. console.log(typeof sum(20,50));
  8. console.log("返回类型为number类型,并且为多个参数");
  9. console.log("+++++++++++++++++++++++");
  10. function getName( ... users){
  11. return users;
  12. }
  13. console.log("参数类型为object类型");
  14. console.log(getName(' 张三 ' , ' 李四 ' , ' 王五' ));
  15. console.log(typeof getName(' 张三 ' , ' 李四 ' , ' 王五' ));
  16. console.log("返回类型为object类型,并且为多个参数");

输出效果图

实例演示模板字面量与模板函数的声明,参数特点

  1. console.log("+++++++++++++++++++++++");
  2. console.log("实例演示模板字面量与模板函数的声明,参数特点 ");
  3. let cat = " 英短 " ;
  4. let fn = function( cat ){
  5. return ' 我家猫的品种 ' + cat ;
  6. };
  7. console.log(fn(`${cat}`));
  8. cat =' 大橘 ' ;
  9. console.log(fn(`${cat}`));

输出效果图

实例演示闭包的形成条件与访问方法,并明白纯函数的特点

  1. console.log("实例演示闭包的形成条件与访问方法,并明白纯函数的特点");
  2. let f1 = function( a ){
  3. return function( b ){
  4. return function( c, d) {
  5. return a* b *c *d;
  6. };
  7. };
  8. };
  9. console.log(f1(8)(6)(5,4));

输出效果图

完整代码如下

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. console.log("函数参数类型与返回值方法");
  12. let sum = function ( a , b){
  13. return a + b;
  14. };
  15. console.log("参数类型为number类型");
  16. console.log(sum(20,50));
  17. console.log(typeof sum(20,50));
  18. console.log("返回类型为number类型,并且为多个参数");
  19. console.log("+++++++++++++++++++++++");
  20. function getName( ... users){
  21. return users;
  22. }
  23. console.log("参数类型为object类型");
  24. console.log(getName(' 张三 ' , ' 李四 ' , ' 王五' ));
  25. console.log(typeof getName(' 张三 ' , ' 李四 ' , ' 王五' ));
  26. console.log("返回类型为object类型,并且为多个参数");
  27. console.log("+++++++++++++++++++++++");
  28. function getNames( username){
  29. //return 'hello '+ ;
  30. return username + ': 你好';
  31. }
  32. console.log("参数类型为string类型");
  33. console.log(getNames(" 丽丽 "));
  34. console.log(typeof getNames(" 丽丽 "));
  35. console.log("返回参数类型为string类型,并且为1个参数");
  36. console.log("+++++++++++++++++++++++");
  37. console.log("+++++++++++++++++++++++");
  38. console.log("实例演示模板字面量与模板函数的声明,参数特点 ");
  39. let cat = " 英短 " ;
  40. let fn = function( cat ){
  41. return ' 我家猫的品种 ' + cat ;
  42. };
  43. console.log(fn(`${cat}`));
  44. cat =' 大橘 ' ;
  45. console.log(fn(`${cat}`));
  46. console.log("+++++++++++++++++++++++");
  47. console.log("实例演示闭包的形成条件与访问方法,并明白纯函数的特点");
  48. let f1 = function( a ){
  49. return function( b ){
  50. return function( c, d) {
  51. return a* b *c *d;
  52. };
  53. };
  54. };
  55. console.log(f1(8)(6)(5,4));
  56. </script>
  57. </body>
  58. </html>

输出效果截图如下

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