Hacker News new | past | comments | ask | show | jobs | submit login

You are doing pass by value on JavaScript example.

For it to be pass by reference you need to change boo inside fun(), but you are changing a field of boo.bar using the boo address passed by value.

When JavaScript starts having pass by reference, this code will hold true. Until then it won't, regardless how people re-invent CS concepts on HN.

  function fun( boo ) {
      boo = { bar: 42 }
  }
  
  function main() {
      let foo = null;
  
      console.log( "Before call:",  foo);
      fun( foo );
      console.log( "After call:", foo );
  }
  
  main();
This will log:

  Before call: null
  After call: { bar: 42 }



Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: