Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Primitive types and properties that are primitive types are pass by value, objects and functions are pass by reference.



It's still pass by value. The value of the object happens to be a reference to a memory location. A primitive also points to a memory location too.


There's no difference

    let a = function bar() { };
    
    function foo( a ) {
      a = 2;
    }
    
    foo( a );
    
    console.log( a ); // bar




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

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

Search: