VSCode Javascript error for string out of bounds
up vote
0
down vote
favorite
I have the following code:
let strA = "0124356789";
let strB = strA.substr(8,3);
console.log(strB);
(I know substr is discouraged, however this is legacy code I need to work with)
Right now VS Code will not complain and will just return strB = 89. I want to get a warning at least that I've tried to reach more chars than there's in strA.
I guess I could write tests that would assert that the length is what is supposed to be, however I'm looking for a simpler solution.
javascript visual-studio-code stringindexoutofbounds
add a comment |
up vote
0
down vote
favorite
I have the following code:
let strA = "0124356789";
let strB = strA.substr(8,3);
console.log(strB);
(I know substr is discouraged, however this is legacy code I need to work with)
Right now VS Code will not complain and will just return strB = 89. I want to get a warning at least that I've tried to reach more chars than there's in strA.
I guess I could write tests that would assert that the length is what is supposed to be, however I'm looking for a simpler solution.
javascript visual-studio-code stringindexoutofbounds
I think writing your own assertion would be the way to go.
– Alex Leo
Nov 8 at 12:04
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have the following code:
let strA = "0124356789";
let strB = strA.substr(8,3);
console.log(strB);
(I know substr is discouraged, however this is legacy code I need to work with)
Right now VS Code will not complain and will just return strB = 89. I want to get a warning at least that I've tried to reach more chars than there's in strA.
I guess I could write tests that would assert that the length is what is supposed to be, however I'm looking for a simpler solution.
javascript visual-studio-code stringindexoutofbounds
I have the following code:
let strA = "0124356789";
let strB = strA.substr(8,3);
console.log(strB);
(I know substr is discouraged, however this is legacy code I need to work with)
Right now VS Code will not complain and will just return strB = 89. I want to get a warning at least that I've tried to reach more chars than there's in strA.
I guess I could write tests that would assert that the length is what is supposed to be, however I'm looking for a simpler solution.
javascript visual-studio-code stringindexoutofbounds
javascript visual-studio-code stringindexoutofbounds
asked Nov 8 at 11:50
Ne Nenne
5117
5117
I think writing your own assertion would be the way to go.
– Alex Leo
Nov 8 at 12:04
add a comment |
I think writing your own assertion would be the way to go.
– Alex Leo
Nov 8 at 12:04
I think writing your own assertion would be the way to go.
– Alex Leo
Nov 8 at 12:04
I think writing your own assertion would be the way to go.
– Alex Leo
Nov 8 at 12:04
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53207164%2fvscode-javascript-error-for-string-out-of-bounds%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I think writing your own assertion would be the way to go.
– Alex Leo
Nov 8 at 12:04