result after execution?pm.test("Check local variable scope", function () { let result = 0; if (true) { let result = 5; } pm.expect(result).to.eql(0); });
let declares block-scoped variables.The variable result declared inside the if block is a different local variable than the one outside. The outer result remains 0, so the test passes.
statusCode set to pm.response.code. Which assertion correctly verifies it equals 200?Option A uses to.equal(200) which correctly asserts the numeric value. Option A compares number to string, causing failure. Option A uses a boolean expression inside expect, which is less clear. Option A uses invalid syntax.
count variable not increment as expected?
let count = 0;
pm.test('Increment count', () => {
let count = count + 1;
pm.expect(count).to.eql(1);
});The inner let count tries to initialize itself with count + 1, but this count refers to itself (not the outer one), causing a ReferenceError.
let inside Postman test scripts?let inside a Postman test script function.Variables declared with let are block-scoped, meaning they exist only inside the block or function where declared. They are not global or shared across requests.
token between multiple pm.test blocks in the same Postman request script. Which approach works best?Declaring token once outside all pm.test blocks makes it accessible inside each test because they share the same function scope. Declaring inside each test creates separate variables. Using pm.variables.set sets environment or collection variables, not local variables. Using var inside a block does not guarantee sharing across tests.