# How to declare and use the variable in Node-Red

**URL:** https://discourse.nodered.org/t/how-to-declare-and-use-the-variable-in-node-red/65030
**Category:** General
**Created:** [13 July 2022 06:16 UTC](https://discourse.nodered.org/t/how-to-declare-and-use-the-variable-in-node-red/65030 "2022-07-13T06:16:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JackJackTan414](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JackJackTan414](https://discourse.nodered.org/u/JackJackTan414)
#### Post date: [13 July 2022 06:16 UTC](https://discourse.nodered.org/t/how-to-declare-and-use-the-variable-in-node-red/65030/1 "2022-07-13T06:16:46Z")

</div>

Hi all , I am doing a simple test which consist of a button node to send the "msg.topic" to the function node when it is pressed via the dashboard UI. Code is shown in the first picture and the second picture shows the error warning when i try to deploy it. I am not sure if this format is correct to initialize the variable and get called when button is pressed.

I am planning to use this variable for the next function node. But first i have to make sure that this first function node is working.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/8/68ec812bd8fcce9a2c6583c61e3deb70f02b9ef0.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/5397375f1a01c954ae55b02df7efe82df050855c.png)

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [13 July 2022 06:27 UTC](https://discourse.nodered.org/t/how-to-declare-and-use-the-variable-in-node-red/65030/2 "2022-07-13T06:27:28Z")

</div>

`a` should be a string (in this case)

`flow.set("a",1)`

`flow.get("a")` = 1

---

<div class="post-metadata">

### Author: ![JackJackTan414](https://avatars.discourse-cdn.com/v4/letter/j/ee59a6/32.png) [@JackJackTan414](https://discourse.nodered.org/u/JackJackTan414)
#### Post date: [13 July 2022 06:53 UTC](https://discourse.nodered.org/t/how-to-declare-and-use-the-variable-in-node-red/65030/3 "2022-07-13T06:53:52Z")

</div>

got it! Thanks a lot!

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [27 July 2022 06:54 UTC](https://discourse.nodered.org/t/how-to-declare-and-use-the-variable-in-node-red/65030/4 "2022-07-27T06:54:39Z")

</div>

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