Blogger Information
Blog 47
fans 0
comment 0
visits 21087
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
JS函数总结
P粉036614676
Original
351 people have browsed it

1.函数参数及其返回值

1.参数传递和引用传递的区别

  1. // let x = (m) => {
  2. // console.log(m);
  3. // }
  4. // let y = x;
  5. // y(10);
  6. // if(x === y)
  7. // {
  8. // console.log(12);
  9. // }
  10. // function sum(obj){
  11. // obj = 10;
  12. // }
  13. // let x = 20;
  14. // sum(x);
  15. // console.log(x);
  16. // function sum(obj){
  17. // obj.name = 10;
  18. // }
  19. // let x = new Object();
  20. // x.name = 20;
  21. // sum(x);
  22. // console.log(x);
  23. // 值传递和引用传递有本质区别,在按引用传递参数时,值在内存中的位置会被保存在一个局部变
  24. // 量,这意味着对本地变量的修改会反映到函数外部。

2.函数类型

  1. function f(){
  2. return 123
  3. }
  4. let y = () => {
  5. return 12;
  6. }
  7. let m = function(){
  8. return 123;
  9. }

3.闭包函数

  1. function f(x){
  2. return function(y)
  3. {
  4. return x * y;
  5. }
  6. }
  7. let m = f(10);
  8. console.log(typeof m);
  9. console.log(m(20));

4.纯函数

没有使用外部变量的函数,可以当成接口函数来使用

  1. let m = (x,y) => {
  2. return x + y;
  3. }
  1. `${}`:JS会将{}中的东西解析出来
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