Search code examples
javascriptfunctioncurly-bracesdollar-sign

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


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


Solution

  • 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.