JS is an interpreted language that doesn't really have an integrated debugger. Hence the easiest way to debug it is to print stuff to the console window as you step through code. For a compiled language this doesn't work because the code is compiled and may or may not run any time soon. These types of languages have an actual debugger that you can run to debug your code.
Without knowing anything else about what you're trying to do I would recommend against the "printf"-style debugging you're used to in JS. It simply isn't needed in a good IDE like Visual Studio. To debug your code set a breakpoint (F9) on the line of code you want to stop at. Run your code in the debugger (F5) and when that line of code is hit you can then step through (F10/F11) the code to verify the behavior, check the state of variables, etc. There is really very little benefit in output window debugging. It requires too much effort and modification of code when you can do much more without any code changes.
Having said that you can print to the program's output window at runtime using the IO functions of the language. You mentioned VSC so I assume you're using C/C++. If you're using C then printf is how you do it.
printf("Will appear in output window at runtime");
In C++ you can still use printf
but the preference is to use cout instead.
cout << "Will appear in output window at runtime";
But all this assumes you're building a console application such that there is an output window. Technically a nodejs is a console app and therefore would behave similarly. However the console window in the browser is really a debugging window and not an output window.
In a language like C/C++ the debugger's Output window is only visible while running in a debugger attached to the IDE (equivalent to the browser's console window). To write to the debugger's output window you would have to call to the OS because debugger's are OS specific. In Windows you use the OutputDebugString function.
OutputDebugString("Will appear only in the debugger's output window while debugging");
In many cases the libraries you're using define a TRACE
macro to make this a little cleaner.
TRACE("Will appear only in the debugger's output window while debugging");
So, in summary, if you want the user to see the output use printf
/cout
. If you only want it for debugging purposes then: a) use the debugger commands instead, b) use OutputDebugString
.