# Local Variable and Environment Variable Precedence

**URL:** <https://community.postman.com/t/local-variable-and-environment-variable-precedence/59912>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [April 13, 2024, 3:14am UTC](https://community.postman.com/t/local-variable-and-environment-variable-precedence/59912 "2024-04-13T03:14:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jais21](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jais21](https://community.postman.com/u/jais21)\
**Post date:** [April 13, 2024, 3:14am UTC](https://community.postman.com/t/local-variable-and-environment-variable-precedence/59912/1 "2024-04-13T03:14:25Z")

</div>

As per variable scope “If a variable with the same name is declared in two different scopes, the value stored in the variable with narrowest scope will be used”.

So, when a local variable and environment variable is declared with same name it should store the local variable. But in the below test it is storing environment variable instead of local variable. I have declared the local variable as let Person\_Name=‘LocalEnv’ in tests.

Is there anything I’m doing wrong or missing out here. Need help/explanation please.

 ![Local variable Vs Environment variable precedence](https://us1.discourse-cdn.com/getpostman/original/3X/d/7/d72e5609c6889f2e5980949d2d0991c7101a6c93.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [April 15, 2024, 4:29pm UTC](https://community.postman.com/t/local-variable-and-environment-variable-precedence/59912/2 "2024-04-15T16:29:59Z")

</div>

Hey @jais21 👋,

Welcome to the Postman Community! :postman:

A local Postman variable would be something that using `pm.variables.set()` and it lives for the duration of the execution of the request/runner etc.

> **[Store and reuse values using variables | Postman Learning Center](https://learning.postman.com/docs/sending-requests/variables/variables/#variable-scopes)**
>
> Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.

> **[Manage API data and workflows using Postman JavaScript objects | Postman...](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#using-variables-in-scripts)**
>
> Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [May 15, 2024, 4:30pm UTC](https://community.postman.com/t/local-variable-and-environment-variable-precedence/59912/3 "2024-05-15T16:30:09Z")

</div>

Closed on May 15, 2024, 4:30pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
