4

I love JS. And then this things happen... I want to learn TypeScript so much (not really related as I don't know if it avoids this).

Btw, I ended up finding ++n works too, so in the end it was 'Question '+ ++n;

Comments
  • 8
    I'm sorry to tell you that's just a result of bad coding not js. Do yourself a favor and skip increment and decrement operators though.
  • 3
    @ScriptCoded +1

    You can't have an intelligent conversation without some risk of offending.
  • 1
    Of course typescript doesn't avoid this. All javascript is valid typescript.
  • 2
    ++n is not the equivalent of the above by the way. It has a side effect, your code above does not.
  • 0
    For clarification, n is the index in an array, *as a string* (coming from Object.entries). So even if I use string interpolation, n+1 ends up being '01' or '11'...
  • 1
    @c3r38r170

    The whole code seems obfuscated.

    Using parentheses you force the right evaluation, but it's a line of code that will get misinterpreted - as you can tell by the people here who fell into the trap.

    While there will be always people trying to prioritize optimization over readability, especially in JS with it's fragile typing system you will shoot yourself or set up a claymore trap for others.

    I'm still unsure what the code actually does - cause a single index doesn't mean there is a single value corresponding to it.

    The simplest thing seems to be a counter variable instead of the parentheses string comcast snafu
  • 0
    This could have been a lot more readable if you used string interpolation.
    And your code will not be the same if you used ++n or n++ because that will leave the side effect of incrementing n which isn't what your code does.
Add Comment