What is wrong with a mathematical operation inside the output of a function result in JavaScript?

  • 0
    Can't figure out what the actual difference is between
    return ["ID DATA", parseInt(oldIdData[0] + oldIdData[1], 2) + 1];

    and
    let resultingIdData = ["ID DATA", parseInt(oldIdData[0] + oldIdData[1], 2) + 1];
    return resultingIdData;

    Why does the first option give an error and the second not? In my opinion, the second ("correct") option is just an irrational increase in the code and the introduction of one more completely unnecessary variable. Moreover, if you remove the addition of unity, the error disappears:
    return ["ID DATA", parseInt(oldIdData[0] + oldIdData[1], 2)];

    The error is indicated when editing the code in the "JetBrains PhpStorm 2020.1" IDE and is described as "Indexed expression can be null or undefined", when the code is executed in the "Mozilla Firefox" and "Google Chrome" browsers, the error does not occur, the execution result is correct. Also, the IDE itself is talking nonsense, since the logic of the code is such that oldIdData [0] and oldIdData [1] when executing the given lines of code exactly contain nonzero valid strings, the result parseInt (oldIdData [0] + oldIdData [1], 2) exactly will give a number.
    JavaScript Anonymous, Mar 19, 2019

  • 0 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!