Variable scope defines where a variable is accessible within Postman. It can be global, collection, environment, data, or local to a request.
Click to reveal answer
beginner
List the order of variable precedence in Postman from highest to lowest.
Local (request) > Data > Environment > Collection > Global variables.
Click to reveal answer
intermediate
Why does a local variable override an environment variable in Postman?
Because local variables have higher precedence, they temporarily override environment variables during request execution.
Click to reveal answer
beginner
How can you set a variable that is accessible across all collections in Postman?
By setting a global variable, which is accessible in all collections and requests.
Click to reveal answer
intermediate
What happens if a variable is defined in both environment and collection scopes with the same name?
The environment variable takes precedence over the collection variable during request execution.
Click to reveal answer
Which variable scope has the highest precedence in Postman?
ALocal (request) variables
BGlobal variables
CEnvironment variables
DCollection variables
✗ Incorrect
Local variables are the most specific and override all other scopes during request execution.
If a variable named 'token' exists in both environment and global scopes, which value is used?
AEnvironment variable value
BGlobal variable value
CBoth values combined
DAn error occurs
✗ Incorrect
Environment variables have higher precedence than global variables.
Where can you set a variable that only applies to a single request in Postman?
AGlobal scope
BEnvironment scope
CLocal (request) scope
DCollection scope
✗ Incorrect
Local variables are specific to a single request and override other scopes.
Which scope is shared across all collections in Postman?
ALocal variables
BCollection variables
CEnvironment variables
DGlobal variables
✗ Incorrect
Global variables are accessible in all collections and requests.
What is the correct order of variable precedence from highest to lowest?
AGlobal > Environment > Collection > Local
BLocal > Data > Environment > Collection > Global
CEnvironment > Global > Collection > Local
DCollection > Global > Environment > Local
✗ Incorrect
Local variables have the highest precedence, followed by data, environment, collection, then global.
Explain variable scope and precedence in Postman with examples.
Think about where variables are set and which ones Postman uses first.
You got /4 concepts.
How does Postman decide which variable value to use when multiple scopes have the same variable name?
Remember the hierarchy from most specific to most general.
You got /4 concepts.
Practice
(1/5)
1. In Postman, which variable scope has the highest precedence when accessing a variable value?
easy
A. Global variables
B. Environment variables
C. Collection variables
D. Local variables
Solution
Step 1: Understand Postman variable scopes
Postman has multiple variable scopes: local, environment, collection, and global.
Step 2: Identify precedence order
Local variables override environment, collection, and global variables when accessing a variable.
Final Answer:
Local variables -> Option D
Quick Check:
Highest precedence = Local variables [OK]
Hint: Local variables always override others in Postman [OK]
Common Mistakes:
Confusing environment variables as highest
Thinking global variables override local
Ignoring local scope existence
2. Which of the following is the correct way to set a local variable in a Postman test script?
easy
A. pm.variables.set('varName', 'value');
B. pm.environment.set('varName', 'value');
C. pm.collectionVariables.set('varName', 'value');
D. pm.globals.set('varName', 'value');
Solution
Step 1: Recall methods to set variables in Postman
Local variables are set using pm.variables.set(). Environment, collection, and global variables use their respective methods.
Step 2: Match method to local variable scope
pm.variables.set() sets a local variable for the current request or script.
Final Answer:
pm.variables.set('varName', 'value'); -> Option A
Quick Check:
Local variable set method = pm.variables.set() [OK]
Hint: Use pm.variables.set() for local variables [OK]
Common Mistakes:
Using pm.environment.set() for local variables
Confusing collection and global variable setters
Forgetting to use pm.variables for local scope
3. Given these variables set in Postman: pm.environment.set('token', 'envToken'); pm.collectionVariables.set('token', 'colToken'); pm.variables.set('token', 'localToken'); What will pm.variables.get('token') return?
But the console logs 'Alice' instead of 'Bob'. What is the issue?
medium
A. pm.environment.set() overwrites local variables
B. pm.variables.set() does not set local variables
C. pm.variables.get() should be used to get local variable
D. pm.environment.get() always reads environment variable ignoring local
Solution
Step 1: Analyze variable setting and getting methods
pm.environment.set() sets environment variable; pm.variables.set() sets local variable. But pm.environment.get() reads environment variable only.
Step 2: Identify correct method to get local variable
To get local variable, use pm.variables.get(), not pm.environment.get().
Final Answer:
pm.variables.get() should be used to get local variable -> Option C
Quick Check:
Use matching get method for variable scope [OK]
Hint: Use pm.variables.get() to read local variables [OK]
Common Mistakes:
Using pm.environment.get() to read local variables
Assuming set method affects all scopes
Expecting pm.variables.set() to overwrite environment
5. You have a global variable 'count' set to '5'. In a collection run, you set a collection variable 'count' to '10'. In a pre-request script, you set a local variable 'count' to '15'. Which value will be used if your test script calls pm.variables.get('count') and why?
hard
A. '15' because local variables have highest precedence
B. '5' because global variables have highest precedence
C. '10' because collection variables override local variables
D. null because variable names conflict
Solution
Step 1: Review variable scopes and precedence
Global variable 'count' = '5', collection variable 'count' = '10', local variable 'count' = '15'. Local variables override collection and global.
Step 2: Determine which value pm.variables.get() returns
pm.variables.get() returns the local variable value if it exists, ignoring collection and global variables.
Final Answer:
'15' because local variables have highest precedence -> Option A
Quick Check:
Local variable value returned by pm.variables.get() [OK]
Hint: Local variables override collection and global variables [OK]
Common Mistakes:
Thinking global variables override local
Assuming collection variables override local
Believing variable conflicts cause null
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.