[ Solved ] Why this code is not working? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

[ Solved ] Why this code is not working?

I learned that JavaScript counts positions from 0. But the following code is not working. Why? <script> var str = "Apple, Banana, Kiwi"; var res = str.substr(-0); document.getElementById("demo").innerHTML = res; </script>

13th Sep 2020, 3:31 PM
Noob Programmer
Noob Programmer - avatar
2 Answers
+ 1
Not enough info.. Add full code.. It assigns full string... 0 or -0 is same
13th Sep 2020, 3:54 PM
Jayakrishna 🇮🇳
+ 2
If the length is 0 or negative value then it returns an empty string. https://code.sololearn.com/WrvCsd9WY3Ss/#html
13th Sep 2020, 3:56 PM
Iraavan 🔥
Iraavan 🔥 - avatar