DEV Community

loading...

Discussion on: 17 Pro JavaScript tricks you didn't know

Collapse
bugb profile image
bugb • Edited

Your code is incorrect

let dynamic = "value"; 
let user = {
    id: 1
    [dynamic] = "other value"
};
Enter fullscreen mode Exit fullscreen mode

It should be

let dynamic = "value"; 
let user = {
    id: 1,
    [dynamic]: "other value"
};
Enter fullscreen mode Exit fullscreen mode
Collapse
rahxuls profile image
Rahul Author

That comma though. I'm sorry

Collapse
adamazad profile image
Adam Azad

So is =. It should be a colon :

let dynamic = "value"; 
let user = {
    id: 1,
    [dynamic]: "other value"
};
Enter fullscreen mode Exit fullscreen mode