Is Space Before Bracket Notation Allowed in JavaScript?

A space before bracket notation is allowed in JavaScript (when setting or getting an object property). For example, the following is valid:

const prop = 'foo';
const obj = { baz: 'qux' };

obj [prop] = 'bar';

console.log(obj [prop]); // 'bar'

This is purely a stylistic preference, and is valid JavaScript syntax.

This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.