TransWikia.com

What is the purpose of an empty value assignment in JavaScript (not null, undefined, etc)

Stack Overflow Asked by user13443583 on November 15, 2021

I understand this:

let blah = null;
let blah = undefined;
let blah;

What I don’t understand is this:

    let obj = {}
      // notice the empty value assignment and the assignment that immediately follows
    obj.blah = 
    obj.blah = function(params) {
      // some code
    }

Is the empty assignment the same as let obj.blah;? I’ve seen this in a few npm packages where the key is provided a value directly beneath the empty value assignment of the same key. Is there a particular purpose to writing code this way? I’m refactoring a package to streamline its use, and I don’t want to simply delete this because of my ignorance. Any help will be greatly appreciated.

One Answer

It's equivalent to

obj.blah = ( obj.blah = function () {} );

There's absolutely no reason to do that.

Answered by Quentin on November 15, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP