I never experienced this one, so I have been struggling it for 4 hours so far.
Let's say we have a button inside template literal.
<button onclick="deleting(${num})" class="btn btn-outline-danger">Delete</button>
deleting function is used for just console.log, meaning that when you click the button, you will see the ${num} value on the console.
Here is the story. My teacher tought me to use .length + 1 function to give a unique number to each card, so I could select and delete a card by clicking the button(each card has the button). I was enjoying it and it was ok to use .length + 1 when I deleted and created the last card. However, when I deleted a card in the middle and created a new card, the card's unique number became overlapped with the last card and all messed up. So, I searched on the Internet and realized that there was nanoid I could give a unique string to each card. Everything seemed to be fine until I faced the button. The problem is when I directly give a value such as 1, 'a', '2' ..., it works fine (console shows the same value), however when I give a value as variable, it shows an error or some weired values.
For example,
<button onclick="deleting(1)" class="btn btn-outline-danger">Delete</button>
=> ok
<button onclick="deleting('2')" class="btn btn-outline-danger">Delete</button>
=> ok
<button onclick="deleting('a')" class="btn btn-outline-danger">Delete</button>
=> ok
let value = '011'
<button onclick="deleting(${value})" class="btn btn-outline-danger">Delete</button>
=> showing 9
let value = 'a'
<button onclick="deleting(${value})" class="btn btn-outline-danger">Delete</button>
=> Uncaught ReferenceError
Can anyone help me understand why these occur and how to fix? and as a learner, I would like to learn if there are some easier and fancier ways to do it, so do not hesitate to share your knowledge with me !!
Thank you guys in advance!
I tried to solve these problems and one of them (011 shows 9) is becasue it shows as octal number when it starts with 00. (I am not sure), but I still have no idea how to make a string value in variable be transferred to an argument inside a function in template literal.