---
title: "Javascript ReferenceError: Invalid Left-hand Side in Assignment"
description: "So lately was trying some silly syntax with javascript, logically it seems to work, but throw away your dry logic! Most of."
url: "https://h3manth.com/scribe/javascript-referenceerror-invalid-left-hand-side-assignment/"
canonical_url: "https://h3manth.com/scribe/javascript-referenceerror-invalid-left-hand-side-assignment/"
markdown_url: "https://h3manth.com/scribe/blog/javascript-referenceerror-invalid-left-hand-side-assignment.md"
publishDate: "2012-06-03T00:00:00.000Z"
author: "Hemanth HM"
category: "javascript"
tags: ["javascript","git"]
word_count: 175
reading_time_minutes: 1
x_markdown_tokens: 384
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Javascript ReferenceError: Invalid Left-hand Side in Assignment

> So lately was trying some silly syntax with javascript, logically it seems to work, but throw away your dry logic! Most of.

**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, /me tried :

> obj={} Object
> 
> obj["prop"] || obj["prop"] = "newprop"
    
    
    ReferenceError: Invalid left-hand side in assignment
    
    arguments: Array[0]
    get message: function () { [native code] }
    get stack: function () { [native code] }
    set message: function () { [native code] }
    set stack: function () { [native code] }
    type: "invalid_lhs_in_assignment"
    __proto__: Error
    

> obj["prop"] = obj["prop"] || "newprop"
> 
> obj.prop "newprop"

## Works this way ^_ ^ 

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

**Finally:**

  * ||= is much needed.
  * obj['prop'] ||= "fun"
  * 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:**

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