Everything is being displayed correctly. It is important to note that in JavaScript, Objects are passed by reference. The variable p1 holds a reference which points to an empty object {} in memory.
When you pass this reference to a method, the variable obj also starts pointing to the same empty object {}. Both variables act as pointers at this stage. If you set obj to null, it means that obj now points to null. However, p1 still points to the empty object {}.
To demonstrate that it is indeed pass by reference,
you can try the following code:
var p1 = { "name" : "demo" }
function passByRef (obj) {
obj.name = "demo updated";
}
//call fun with p1
passByRef(p1);
// print p1.name -> it will be the updated one
console.log(p.name);
Therefore, JavaScript behaves similarly to Java where function arguments are passed by reference.