-2

What are the exact meanings and differences using these values in JS : ${abc} vs {abc} vs (abc)

Rahul Ahire
  • 685
  • 11
  • 28
  • 3
    None of those appear to be Booleans. All of that syntax has different meanings in different contexts. – Quentin Apr 02 '20 at 12:56
  • Why is this tagged [tag:reactjs], [tag:function], and [tag:react-functional-component]? This doesn't seem to be related to any of those (although one of the aforementioned different contexts for `{...}` is in JSX which is commonly used with React) – Quentin Apr 02 '20 at 12:58
  • `${abc}` is the syntax for a substitution in a template literal (```console.log(`abc is ${abc}`);```). `{abc}` is a JSX expression you'd use in a JSX context (``). `(abc)` is just a variable reference within parentheses (which are unnecessary when the only thing inside them is a variable reference). – T.J. Crowder Apr 02 '20 at 13:03
  • thanks all for your valuable feedbacks I've updated the question – Rahul Ahire Apr 02 '20 at 13:18

1 Answers1

-1

None of those have to be boolean values. ${abc} is used inside template strings to embed an expression inside a string.

`foo ${abc} bar`

is equivalent to

"foo " + abc + " bar"

{abc} is an object shorthand notation that's equivalent to {abc: abc}. (abc) is just abc surrounded by parenthesis, which is equivalent to abc.

Aplet123
  • 33,825
  • 1
  • 29
  • 55