I read the following code inside a react function return statement.
return(){
<span className="expense">{charge}</span>
<span className="amount">${amount}</span>
}
My question is with or without $, they just represent a dynamic variable to be rendered right? I saw ${} and {} sometimes interspersed in code and got really confused if they should be interchangeable. Thanks.
To embed expressions into JSX, you'll use only curly braces. The $ is outside the curly braces, and is therefore interpreted as text.
<div>${145}</div>
// equals
<div>$145</div>
Inside template literals however, the syntax for embedding expressions is ${...}
:
`Amount: ${145}`
// equals
`Amount: 145`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With