Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

with or without dollar sign in react [duplicate]

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.

like image 404
Olivia Chen Avatar asked Sep 08 '25 11:09

Olivia Chen


1 Answers

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`
like image 58
Jonas Wilms Avatar answered Sep 10 '25 02:09

Jonas Wilms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!