with spaces, it would be work like usual string with space behavior
Current
const name = 'name with space'
const obj = {name}
console.log(obj)
// output => {'name-with-space': 'name with space'}
With this proposal
const obj = {'value with space'}
console.log(obj)
// output => {'value-with-space' : 'value with space' }
Pros
As we can see from this examples, we need a separate variable to do this shorthand (ofcourse we can avoid using this separate variable but then we cant do this shorthand) with this proposal, we dont need that extra variable for doing this shorthand.
Cons
May be some conflict with rare cases. I didnt find any as of now. Please do let me know if you think
when I mean value with space. The key has to be filled with dashes as I think keys having spaces in it might have limited access approach like
if its
const a = {
'value with space' : 'value with space'
}
it is possible, fare enough !
but we can access it only using this a[value with space] not using this a.value with space
ALso, I made a mistake in the post with adding - instead of underscrore (_) in the keyso I think it should be{ value_with_space : 'value with space' }. this is just for safe side. We can surely omit any kind special char and keep the space as it is even for thekey` and that would work fine as well cause JS allows that so it will