You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Linux [my-computer-hostname] 5.13.0-35-generic #40~20.04.1-Ubuntu SMP Mon Mar 7 09:18:32 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
1: Assign numeric values from process.argv[] to variables declared with let (i.e. let x=process.argv[2]; let y=process.argv[3]; let z=process.argv[4]
2: Perform some basic arithmetic on those variables (i.e. let answer=x*(y+z);)
3: See ridiculous output (above answer would come out as x * y.concat(z);)
Testing code that I'm using:
letx=process.argv[2];lety=process.argv[3];letz=process.argv[4];console.log("Using values from process.argv[]:");console.log(`x=${x} | y=${y} | z=${z}`);console.log(`x-y=${x-y}\nx/y=${x/y}\nx*(y+z)=${x*(y+z)}`);leta=1;letb=2;letc=3;letanswer=a*(b+c);console.log("\n\nUsing values declared within the script:");console.log(`a=${a} | b=${b} | z=${c}`);console.log(`a-b=${a-b}\na/b=${a/b}\na*(b+c)=${a*(b+c)}`);
How often does it reproduce? Is there a required condition?
Always. Seems to be a variable type auto-detect error when using numeric values from process.argv[]
The values coming from process.argv are strings. The + operator performs string concatenation or addition, depending on the type of the values being used, while the -, *, and / operators convert the values to numbers first.
This is not specific to Node.js. You can try it in a browser or Deno as well. Closing as working as intended.
Version
17.8.1
Platform
Linux [my-computer-hostname] 5.13.0-35-generic #40~20.04.1-Ubuntu SMP Mon Mar 7 09:18:32 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Subsystem
No response
What steps will reproduce the bug?
1: Assign numeric values from process.argv[] to variables declared with let (i.e. let x=process.argv[2]; let y=process.argv[3]; let z=process.argv[4]
2: Perform some basic arithmetic on those variables (i.e. let answer=x*(y+z);)
3: See ridiculous output (above answer would come out as x * y.concat(z);)
Testing code that I'm using:
How often does it reproduce? Is there a required condition?
Always. Seems to be a variable type auto-detect error when using numeric values from process.argv[]
What is the expected behavior?
What do you see instead?
Additional information
No response
The text was updated successfully, but these errors were encountered: