Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
![](/static/devrant/img/pipeless-devrant-banner-white.png)
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
I'll guess JavaShit eh JavaScript.
You're correct. charAt and substring are 0 indexed, thus equal as both return on invalid ranges an empty string and 0 is always first index. -
-
@dan-pud I did, but my confidence is still somehow lacking in case I've booked something up this ridiculously simple.
Java though, I should have mentioned. -
@AlmondSauce *pats your ego* don't get hard.
*hrhrhhr*
Na it's fine to look up stuff. Small things matter. Eg. Multibyte handling. Impossible to know all the caveats in all languages -
asgs115153yAre you the reviewer or reviewee?
If former, remove yourself and let him have fun fixing bugs later
If latter, you could get someone sane enough to provide you the requisite approval -
Three ways to ask him would be
a) "if you run "abc".substring(0,1)" in the DevTools console what do you get?
b) look at the function definition on mdn. The second argument is optional. So obviously substring(0) gets the first item!
c) If what YOU'RE saying is true - how would you get the first item? Would the first argument be set to -1? That would be weird wouldn't it? -
PS: I truly hope you're not actually arguing about what a specific line of code does ... as it's so easy to test it in DevTools.
I assume you're arguing about how to write a function that uses variables in place of the arguments.
And this is what's causing confusion. -
Open up jshell, do
> var s = "hello";
> s.charAt(0);
'h'
> s.charAt(1);
'e'
> s.substring(0, 1);
'h'
>
and post him the output
Arguing with a guy in a PR that substring(0,1) (first index inclusive, last exclusive) is equal to charAt(0), whereas he seems to think it's charAt(1).
My patience is wearing thin, but I now feel the need to check I'm not the moron here - someone please confirm if I'm the idiot here or not?
rant