Please explain in simple terms, what does the bracket notation in JavaScript provide? Why is it sometimes better than directly assigning an object property?

    1 answer 1

    Used when the name of a property includes invalid characters:

    obj['with space'] = '...' obj['with-dash'] = '...' 

    Or when it is not yet defined.

     function setProps(someName) { obj[someName] = '...' obj2 = { [someName]: '...' } } 

    To create iterators

     const iterator = obj[Symbol.iterator]() iterator.next()