Why does a file get opened when I write its name, without extensions, in the command line?

Because %PATHEXT% is set to .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC by default. Note how it contains .js.

That means if you type a name, CMD will look for files with these extensions appended, in that order, in the current folder. Only after that will it consider what’s in %PATH%. This behavior cannot be changed. You can modify %PATHEXT% though, like any other environment variable.

You can use the WHERE command to check which path would be opened (e.g. where truffle), which will automatically search both %PATH% and %PATHEXT% the same way CMD would.