The German conjunctions "denn" and "weil" do not have a difference in meaning. If you can use "denn" in a sentence, you could have expressed the very same sentence using "weil" - and vice versa. However, you cannot just swap them out for one another.
While there is not difference in meaning between "weil" & "denn", they are not interchangable: You cannot simply take a sentence that uses "weil" and replace "weil" with "denn".
The reason for this is that weil & denn "dock onto" different sentence structures. "Weil" requires a subordinate clause, whereas "denn" requires a main clause. Let's have a look at sentence using weil:
Ich trinke ein Glas Wasser, weil ich Durst habe.
What comes after "weil" cannot stand on its own.
It's a subordinate clause. "
Ich Durst habe" is not be a correct sentence in German.
"Denn", however, works differently to "weil". It introduces a main clause. So the very same sentence with "denn" has a slightly different word order:
Ich trinke ein Glas Wasser, denn ich habe Durst.
"Ich habe Durst" can stand on it's own: it's a main clause.
And this is the reason why you cannot just swap "weil" & "denn" out however you please.
Another difference is that "denn" can never stand at the beginning of a sentence. You cannot introduce a sentence with "denn".
So you could say:
Weil ich Angst hatte, blieb ich in der Wohnung.
But you could not say:
Denn ich Angst hatte, blieb ich in der Wohnung.
Here are two more basic dialogues using "weil":
And here are two example dialogues using "denn":