-1

I've got a very simple calculator app:

if (process.argv[3]==='+') console.log(parseInt(process.argv[2]) + parseInt(process.argv[4]));
if (process.argv[3]==='-') console.log(parseInt(process.argv[2]) - parseInt(process.argv[4]));
if (process.argv[3]==='*') console.log(parseInt(process.argv[2]) * parseInt(process.argv[4]));
if (process.argv[3]==='/') console.log(parseInt(process.argv[2]) / parseInt(process.argv[4]));
console.log(process.argv[3])  

2 + 2, 2 - 2, 2 / 2 all work as expected, but 2 * 2 will log out the name of the script.
Why does this happen? What is it about the multiplication sign?

Jay Jung
  • 1,343
  • 14
  • 37
  • Not an expert but maybe something to do with wild cards? Like when you want to list all js files and do "*.js"... – cbuchart Mar 31 '17 at 05:57

1 Answers1

1

It's because * is a shell wildcard, It has a special meaning to the shell, which expands it before passing it to the node.

You have to pass it with \* like this or "*" or like this '*'.

Gaurav Gandhi
  • 2,536
  • 2
  • 23
  • 35