Guest User

Untitled

a guest
Jan 12th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. const a = {
  2. x: 0
  3. };
  4. const f = function(a) {
  5. a.x = 100;
  6. }
  7. f(a);
  8. console.log(a);
  9. // will print { x: 100 }
  10.  
  11. // =================================
  12.  
  13. const a = {
  14. x:0
  15. };
  16. const f = function(a) {
  17. a = 'foo';
  18. }
  19. f(a);
  20. console.log(a);
  21. // will print { x: 0 }
  22.  
  23.  
  24. You're talking about calling a function "by reference". JavaScript (like most other functional languages) doesn't support that, as, changing a variable that is outside the current scope is a side-effect and those contradict functional programming paradigms.
  25. You can always change variables inside the current scope though. So any function defined within another function can change any local variable of the outer one.
Add Comment
Please, Sign In to add comment