---
title: "JavaScript ReferenceError: Invalid left-hand side in assignment"
description: "Exploring interesting JavaScript reference errors and learning about ||= operator. Practical notes and code examples on."
url: "https://h3manth.com/scribe/javascript-referenceerror-invalid-left-hand-side-in-assignment/"
canonical_url: "https://h3manth.com/scribe/javascript-referenceerror-invalid-left-hand-side-in-assignment/"
markdown_url: "https://h3manth.com/scribe/blog/javascript-referenceerror-invalid-left-hand-side-in-assignment.md"
publishDate: "2012-06-02T00:00:00.000Z"
author: "Hemanth HM"
category: "javascript"
tags: ["javascript"]
word_count: 143
reading_time_minutes: 1
x_markdown_tokens: 331
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# JavaScript ReferenceError: Invalid left-hand side in assignment

> Exploring interesting JavaScript reference errors and learning about ||= operator. Practical notes and code examples on.

**So lately was trying some silly syntax with JavaScript, logically it seems to work, but throw away your dry logic!**

Most of us who have been pawing at some raw JS knows `undefined || "hi"` would result in `"hi"`, on the same lines, I tried:

```javascript
> obj = {}
Object

> obj["prop"] || obj["prop"] = "newprop"
   
ReferenceError: Invalid left-hand side in assignment
    type: "invalid_lhs_in_assignment"
 
> obj["prop"] = obj["prop"] || "newprop"

> obj.prop
"newprop"

// Works this way ^_^
```

One of my friend @Altreus said **"Lack of ||= saddens me"** and @jasonmulligan's [solution](https://github.com/avoidwork/abaaso/blob/master/debug/abaaso.js#L3349) helped!

**Finally:**

* `||=` is much needed.
* `obj['prop'] ||= "fun"` would be nice!
* There is already a proposal in ES5 for this now!

**Happy hacking, hope we shall have more fun with more JS :)**

**EDIT 0** suggested by charliesome:

```javascript
obj["prop"] || (obj["prop"] = "newprop");
```
