2

I was come across the code which was written in following way:

var myStr = ('abc');
console.log(myStr)  // output: 'abc'
myStr === 'abc'  // true

What was the use of () in above example?

michal.jakubeczy
  • 4,457
  • 1
  • 30
  • 43
sagar735
  • 43
  • 1
  • 6
  • 7
    There is no purpose in your example. It's a grouping operator and you are grouping no operations together, so it's equivalent to not using it. Same as how `5 + (1)` is the same as `5 + 1` – VLAZ Sep 10 '19 at 16:13
  • 1
    I usually use it when using arrow operators that return an object literal. `const fn = () => ({a: 1})` – Get Off My Lawn Sep 10 '19 at 16:14
  • 5
    Can we not fill the comments up with examples of how grouping operators are used in obscure contexts that the question isn't asking about? – Quentin Sep 10 '19 at 16:17

0 Answers0