Returns the wrong character in SubString method

Viewed 348

I am new to JS, i have tried the below code,

var str = "\">2\""
var res = str.substring(2,1);

Return: >

Expected: 2

I have checked this by below code,

var str = "\">2\""
var res = str.substring(2);

Return: "2\"

Expected: "2\"

Please let me know if i misunderstand anything, why it returns > instead of 2. In C# it works correctly.

Thanks in advance

3 Answers
Related