Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is string with dollar sign not working in javascript function? [closed]

Tags:

javascript

why doesn't the word apple doesn't appear using function inside function . I tried many times with different words but not working the result is always it is ${fuit}

const firstfunction=(fuit)=>{
    const gettingbrackets='it is   ${fuit}'
    console.log (gettingbrackets)
}
firstfunction('apple')
like image 213
Osama Avatar asked Apr 27 '26 12:04

Osama


1 Answers

You have used the wrong quotation marks. You need to use backtick `` character instead of single ' (or double ") quotes. For more details please read the docs about Template literals carefully

const firstfunction=(fuit)=>{
    const gettingbrackets=`it is   ${fuit}`
    console.log (gettingbrackets)
}
firstfunction('apple')
like image 76
caramba Avatar answered Apr 30 '26 02:04

caramba



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!