3

The ${} is template literals. What's {} without the $ sign?

In React:

function App(){
    return(<div temp={3}></div>);
}

(I was looking up the difference and nothing came up. So, I think this question is needed as I couldn't know if I was using JS or JSX.)

6
  • Does this answer your question? What do curly braces mean in JSX (React)?
    – user12273078
    Commented Jul 31, 2020 at 12:23
  • You use ${} in string templates like const k = `my name is ${name}` you use {} whenever you want to put some Java code in your JSX code like <div attr={name}>{name}</div>
    – Nishant
    Commented Jul 31, 2020 at 12:23
  • @Megapteranovaeangliae I was looking up the difference and nothing came up. So, I think this question is needed as I couldn't knew if i was using js or jsx. Commented Jul 31, 2020 at 12:28
  • You tagged this reactjs so you surely must have had some idea you were looking at something which was not vanilla javascipt?
    – Jamiec
    Commented Jul 31, 2020 at 12:28
  • @Jamiec Its funny, i don't know anything about reactjs. Its the first time ever. I've heard there's JSX in react but the tutorial I'm following says it only use vanilla javascript. (And even said JSX is hard for beginners and they wont use it) Commented Jul 31, 2020 at 12:32

1 Answer 1

4

You're quite correct that javascript uses ${} to make use of template literals within strings surrounded by backticks `

The code you pasted is not javascript, it is JSX and the { and } is how you embed expressions within it.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.