# What kind of variable is it?

**URL:** <https://community.postman.com/t/what-kind-of-variable-is-it/55238>\
**Category:** Help Hub\
**Tags:** variables\
**Created:** [December 3, 2023, 3:01pm UTC](https://community.postman.com/t/what-kind-of-variable-is-it/55238 "2023-12-03T15:01:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![marigen00](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/marigen00/32/26712_2.png) [@marigen00](https://community.postman.com/u/marigen00)\
**Post date:** [December 3, 2023, 3:01pm UTC](https://community.postman.com/t/what-kind-of-variable-is-it/55238/1 "2023-12-03T15:01:35Z")

</div>

Hi everyone  
I’m not good in the theory. So I’ve got a question about variables.  
There are variables:

```auto
firstVar = "value 1"
pm.variables.set("firstVar", "value 2")
pm.variables.set("secondVar", "value 3")

console.log(firstVar)
console.log(pm.variables.get("firstVar"))
console.log(pm.variables.get("secondVar"))

```

Following postman docs `pm.variables.set()` sets a local variable.  
But I haven’t found the name of variable without `pm.variables.set()`.  
It works differently. I get how to work ith it but I want to be better in the theory.

Tell me please what kind of variable is it?

---

<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:** [December 4, 2023, 1:31pm UTC](https://community.postman.com/t/what-kind-of-variable-is-it/55238/2 "2023-12-04T13:31:39Z")

</div>

Hey @marigen00 👋

Welcome to the Postman Community! :postman:

There are a number of different variable scopes within Postman and their usage depends on the context.

> **[Store and reuse values using variables | Postman Learning Center](https://learning.postman.com/docs/sending-requests/variables/#variable-scopes)**
>
> Store and reuse values using variables: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

When you set a variable value using `pm.variables.set` , the value is local and will only persist for the current request or collection run. That value doesn’t get stored anywhere and cannot be reused outside of that request.

When using `pm.variables.get()` it’s slightly different, that will search through each variable scope (global, collection, environment, data, local(_using pm.variables.set())_) and return the variable in the narrowest scope, if it has the same name.

> **[Manage API data and workflows using Postman JavaScript objects | Postman...](https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#the-pm-object)**
>
> Manage API data and workflows using Postman JavaScript objects: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

For example, saving a variable with the same name to the Collection and Global scope, would log the Collection variable to the console as it has the narrowest scope.

```auto
pm.collectionVariables.set("name", "danny");
pm.globals.set("name", "danny");

console.log(pm.variables.get("name"));

```

 ![Screenshot 2023-12-04 at 13.26.59](https://us1.discourse-cdn.com/getpostman/original/3X/3/7/37e365306116ad9a4cb3216953a329ee6162df40.png)

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/1/f1370c57ab1ec7c9ebd1e7239462b712f4d667b7.jpeg)

I’m more than happy to expand on the information here if you have follow up questions.

---

<div class="post-metadata">

**Author:** ![marigen00](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/marigen00/32/26712_2.png) [@marigen00](https://community.postman.com/u/marigen00)\
**Post date:** [December 4, 2023, 7:18pm UTC](https://community.postman.com/t/what-kind-of-variable-is-it/55238/3 "2023-12-04T19:18:34Z")

</div>

Thank you for your answer with pm.\*\*\*\*(). You helped to correct my question.  
What is the scope of variables without postman/pm. commands?  
Is it also local variable but in JS scope?  
Or am i wrong?

---

<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:** [December 4, 2023, 7:53pm UTC](https://community.postman.com/t/what-kind-of-variable-is-it/55238/4 "2023-12-04T19:53:16Z")

</div>

Those are the standard JS declared variables (var, let, const) and can be used within the sandbox.

For more detailed information around those, I would recommend taking a look over this documentation:

> **[JavaScript reference - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference#declaring_variables)**
>
> The JavaScript reference serves as a repository of facts about the JavaScript language. The entire language is described here in detail. As you write JavaScript code, you'll refer to these pages often (thus the title "JavaScript reference").

---

<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:** [December 8, 2023, 8:11am UTC](https://community.postman.com/t/what-kind-of-variable-is-it/55238/5 "2023-12-08T08:11:06Z")

</div>

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