In A Doll's House, the masquerade party is symbolic in that Nora wears a mask daily. She keeps up a facade on a regular basis. She pretends she is happy when she is not. She cannot even eat a macaroon without Torvald scolding her for it.
Ultimately, Nora has had enough of Torvald's games. She is tired of playing house. She cannot pretend to be his doll any longer. She must find her own identity. In so doing, she must leave Torvald first. When she slams the door, she is opening herself up to a new life, one in which she can find her own identity.
The foreshadowing of Nora's change at the end of the play happens when she is talking with Dr. Rank earlier in the play in Act I. She insists that she is going to tell Torvald what she is really thinking. About this time, Torvald comes out of his office, and Dr. Rank says, "Say it. Here he is." Nora says nothing.
This is an indication that Nora is not happy. For this reason, the author indicates that Nora's leaving is a necessity and is the right thing to do. The author causes the reader to sympathize with Nora. Torvald is obnoxious. It is easy for the reader to dislike Torvald. When Nora slams the door to leave, the reader is relieved for Nora's sake.