What is the difference between initializing variables using var vs pm.variables.set?


In a collection with multiple requests, if I create a variables like this in Pre-requests Scripts or Tests of one of the requests:

var myVar1 = "I am created using var";
pm.variables.set("myVar2", "I am created using pm.variables.set");

I have seen both methods been used and I searched what the differences would be but I couldn’t find any useful explanations. I hoped to find it here https://learning.postman.com/docs/sending-requests/variables/#variable-scopes, but that is not described.

Writing this post I see a message my question might have answers on https://testing-one-2-three.postman.co/home, but I can’t seem to access that.

What is the difference between using var and pm.variables.set and when would you use which method?

Thanks, Jaap