# How to change project's variables values with Custom Javascript?

**URL:** <https://community.weweb.io/t/how-to-change-projects-variables-values-with-custom-javascript/7179>\
**Category:** How do I?\
**Tags:** binding\
**Created:** [February 22, 2024, 2:12pm UTC](https://community.weweb.io/t/how-to-change-projects-variables-values-with-custom-javascript/7179 "2024-02-22T14:12:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LivingStoneHgS](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LivingStoneHgS](https://community.weweb.io/u/LivingStoneHgS)\
**Post date:** [February 22, 2024, 2:12pm UTC](https://community.weweb.io/t/how-to-change-projects-variables-values-with-custom-javascript/7179/1 "2024-02-22T14:12:25Z")

</div>

Hi there,

I have a Custom Javascript code into my component’s workflow, and I want to change a component’s variable (but let’s extend the question to any variable) value into this code. But when I click the variable to have its reference and set it to a new value, like :  
`context.component?.variables?.['36fad30d-9163-4321-a83b-28a8a3be3bf1'] = 10;`

… then I have an error in the console :

`name: "SyntaxError"`  
`stack: "SyntaxError: Invalid left-hand side in assignment at executeCode ...`  
`message: "Invalid left-hand side in assignment"`

… which let me guess I might not be allowed to do this. I could return an object and set another action ‘Change variable value’ thanks to that object but it’s less concise.

Thanks to let me know the good ways.

👋

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [February 22, 2024, 2:17pm UTC](https://community.weweb.io/t/how-to-change-projects-variables-values-with-custom-javascript/7179/2 "2024-02-22T14:17:38Z")

</div>

> [@LivingStoneHgS](#):
>
> SyntaxError: Invalid left-hand side in assignment at executeCode

> **[SyntaxError: invalid assignment left-hand side - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_assignment_left-hand_side#using_optional_chaining_as_assignment_target)**
>
> The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. It may be triggered when a single = sign was used instead of == or ===.

---

<div class="post-metadata">

**Author:** ![LivingStoneHgS](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LivingStoneHgS](https://community.weweb.io/u/LivingStoneHgS)\
**Post date:** [February 22, 2024, 2:29pm UTC](https://community.weweb.io/t/how-to-change-projects-variables-values-with-custom-javascript/7179/3 "2024-02-22T14:29:50Z")

</div>

Ah ok, it’s due to optional chaining… thanks !

---

<div class="post-metadata">

**Author:** ![Antiokh](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/antiokh/32/2794_2.png) [@Antiokh](https://community.weweb.io/u/Antiokh)\
**Post date:** [April 28, 2024, 10:42pm UTC](https://community.weweb.io/t/how-to-change-projects-variables-values-with-custom-javascript/7179/4 "2024-04-28T22:42:44Z")

</div>

Tell me please, how you’ve changed your assignment?

---

<div class="post-metadata">

**Author:** ![LivingStoneHgS](https://avatars.discourse-cdn.com/v4/letter/l/439d5e/32.png) [@LivingStoneHgS](https://community.weweb.io/u/LivingStoneHgS)\
**Post date:** [April 30, 2024, 2:07pm UTC](https://community.weweb.io/t/how-to-change-projects-variables-values-with-custom-javascript/7179/5 "2024-04-30T14:07:55Z")

</div>

Hi, either set an imperative assignment, or use an “if” condition :

> **[SyntaxError: invalid assignment left-hand side - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_assignment_left-hand_side#using_optional_chaining_as_assignment_target)**
>
> The JavaScript exception "invalid assignment left-hand side" occurs when there was an unexpected assignment somewhere. It may be triggered when a single = sign was used instead of == or ===.

---

<div class="post-metadata">

**Author:** ![Antiokh](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/antiokh/32/2794_2.png) [@Antiokh](https://community.weweb.io/u/Antiokh)\
**Post date:** [May 1, 2024, 10:10pm UTC](https://community.weweb.io/t/how-to-change-projects-variables-values-with-custom-javascript/7179/6 "2024-05-01T22:10:30Z")

</div>

Got it. So the problem was with the undefined in the middle of object path row.
