1

I am not Javascript developer and try to learn this language .
so i can not found any reference for this question on internet .
What does mean variable inside parentheses ?
For example what is different between :

(name) = "Julia" ;
name="Julia" ;    
mah454
  • 1,571
  • 15
  • 38
  • Could you link an example code, from where you got this piece? – Andrey Bodoev Feb 18 '21 at 08:38
  • I normally see parenthesis as a [Grouping operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Grouping) - the code you pasted does not make any special sense – mplungjan Feb 18 '21 at 08:38
  • This would just create globally scoped variable, I think. The parentheses are basically ignored. – NullDev Feb 18 '21 at 08:39
  • 2
    @mplungjan it's weird - it's *not* the grouping operator, since [`(x, name) = "Julia"`](https://jsbin.com/nisomoyuhi/edit?js,console) doesn't work. It seems the brackets are ignored. [AST explorer](https://astexplorer.net/#/gist/dee0abc696da9f4409d3059d2bb76671/0eb0b02d83a5eb7278a61c5038bd471e8a457685) doesn't seem to mention the brackets. – VLAZ Feb 18 '21 at 08:40
  • I personally ONLY use brackets in math and in the old days before template literals: `var text = (some statement) + (someBoolean ? "x" : "y")` – mplungjan Feb 18 '21 at 08:46
  • @AndreyBodoev this is persian language so i send google translated language link for you : https://translate.google.com/translate?sl=fa&tl=en&u=https://cdn.tsetmc.com/Site.aspx?ParTree%3D151713 – mah454 Feb 18 '21 at 08:54
  • @mah454 in provided link I didn't see any assignments with `()`, but what I see it's only relational and equality operators, and `(plc)` meaning they have set a variable before, like so `var plc = 1; (plc) <= 100` – Andrey Bodoev Feb 18 '21 at 09:04
  • @AndreyBodoev Thank you , but why variable inside parentheses ? – mah454 Feb 18 '21 at 09:16
  • @mah454 no idea, my wild guess its emphasis on reserved variables (that's why they provide table with explanation) and bad style, but not wrong though – Andrey Bodoev Feb 18 '21 at 09:29
  • I marked the question as a duplicate against a slightly newer one because I think the newer one is more widely applicable. The answer is good. The reason why `(name) = "Julia"` works is because when you use the grouping operator on an expression, `(name)` is the same as just `name` for the purposes of assignment. So `(name) = "Julia"` is the same as just `name = "Julia"`. The brackets are superfluous in this one case. – VLAZ Feb 18 '21 at 09:32

0 Answers0