DEV Community

kambala yashwanth
kambala yashwanth

Posted on

 

Obj initialization same key_and_value

var k_as_v = "k_as_v";
obj = {

    [k_as_v]:k_as_v,

}

console.log(obj);

Why cant I just keep k_as_v

var k_as_v ="k_as_v";

obj = {

   [k_as_v],

}

console.log(obj);

If cant how can i achieve this without re-declaring, any hack !

Top comments (4)

Collapse
 
rhymes profile image
rhymes

Just remove the square brackets.

{ kasv }

Collapse
 
yashwanth2804 profile image
kambala yashwanth

No mate , not working
jsbin.com/nuboloqaqi/edit?js,console

Collapse
 
rhymes profile image
rhymes

One set of curly brackets too many.

Obj = { kasv }

Thread Thread
 
yashwanth2804 profile image
kambala yashwanth

Thank you, Done !

An Animated Guide to Node.js Event Loop

Node.js doesn’t stop from running other operations because of Libuv, a C++ library responsible for the event loop and asynchronously handling tasks such as network requests, DNS resolution, file system operations, data encryption, etc.

What happens under the hood when Node.js works on tasks such as database queries? We will explore it by following this piece of code step by step.